Friday 14 April 2017

AngularJS AJAX - $http

AngularJS AJAX - $http
$http is an AngularJS service for reading data from remote servers.

AngularJS $http
The AngularJS $http service makes a request to the server, and returns a response.

 <div ng-app="myApp" ng-controller="myCtrl">   
 <p>Today's welcome message is:</p>  
 <h1>{{myWelcome}}</h1>  
 </div>  
 <script>  
 var app = angular.module('myApp', []);  
 app.controller('myCtrl', function($scope, $http) {  
   $http.get("welcome.htm")  
   .then(function(response) {  
     $scope.myWelcome = response.data;  
   });  
 });  
 </script>  

Methods
The example above uses the .get method of the $http service.

The .get method is a shortcut method of the $http service. There are several shortcut methods:

.delete()
.get()
.head()
.jsonp()
.patch()
.post()
.put()

The methods above are all shortcuts of calling the $http service:

 var app = angular.module('myApp', []);  
 app.controller('myCtrl', function($scope, $http) {  
   $http({  
     method : "GET",  
     url : "welcome.htm"  
   }).then(function mySucces(response) {  
     $scope.myWelcome = response.data;  
   }, function myError(response) {  
     $scope.myWelcome = response.statusText;  
   });  
 });  

The example above executes the $http service with an object as an argument. The object is specifying the HTTP method, the url, what to do on success, and what to do on failure.


1 comment:

  1. Thanks for sharing, nice post!

    Tìm hiểu http://mayduavong.me/nen-mua-may-dua-vong-tu-dong-loai-nao-tot-nhat-gia-bao-nhieu/ và địa chỉ uy tín tại Hà Nội và TP.HCM bán http://anthaison.vn/sp/may-dua-vong-tu-dong-ts/ máy đưa võng chất lượng nhất, pediakid d3 có tốt không nên dùng cho trẻ mấy tháng tuổi, siro hỗ trợ tiêu hóa Pediakid Transit Doux cho trẻ có tốt không, siro tăng cường trí não cho trẻ pediakid omega 3 có tốt không có tốt không, bột uống pediakid tăng chiều cao có tốt không, hay siro nào tốt cho trẻ biếng ăn kích thích trẻ ăn ngon.

    ReplyDelete

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (43) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (47) CD (1) CI (2) CloudComputing (2) Coding (7) CQRS (1) CSS (2) Design_Pattern (6) DevOps (4) DI (3) Dotnet (8) DotnetCore (16) Entity Framework (2) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) Lamda (3) Linq (11) microservice (3) Mongodb (1) MVC (46) NodeJS (8) React (11) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (1) UI (1) UnitTest (1) WCF (14) Web Api (15) Web Service (1) XMl (1)

Dotnet Guru Archives