Bottom line: They angular each stage of the framework's declaration cycle, and the general conventions focus on specific functions, which can be handled or replaced with each other.
1. function Subdivision Simple solution
$http |
Like jquery Ajax, Support promise |
$http. Jsonp |
Cross-domain access, support for JSON data format only, no support for text, HTML and other formats |
$httpProvider |
Mainly used in config, do http common settings |
1 <label>JSONP instances, Http promise instances</label>2 <DivNg-controller= "Jsonpcontroller">3 <DivID= "Baidu">4HTTP promise: {{hpromise}}<P></P>5 Jsonp: {{jsp}}6 </Div>7 <Script>8 varmyApp=Angular.module ('myApp', []);9 Ten Myapp.controller ('Jsonpcontroller', function($scope, $http) { One $http. JSONP ("Https://api.github.com?callback=JSON_CALLBACK"). Success (function(data) { A $scope. JSP=data; - }); - the varPromise=$http ({ - Method:'GET', - URL:'https://api.github.com' - }); + promise.success (function(data, status, headers, config) { - $scope. Hpromise=Data.current_user_url; + A }); at Promise.error (function(data, status, headers, config) { - scope.hpromise= 'hpromise'; - }); - - }); - </Script> in </Div> - to <P></P> + <label>$httpProvider instances</label> - <Pre> the angular.module (' myApp ', []) * . config (function ($httpProvider) { $ $httpProvider. Defaults.headersPanax Notoginseng . common[' x-requested-by '] = ' myangularapp '; - }); the </Pre>
2. View the results of the operation online
Http://jimuyouyou.github.io/angular-bootstrap-rest-seed/examples/angular/8-ajax.html
3. Project Address
Github:https://github.com/jimuyouyou/angular-bootstrap-rest-seed
Jane Angular Angular Ajax