$http service is used to get data from remote server. It makes HTTP request to get data.
Following are methods available in $http service:
.get()
.put()
.post()
.delete()
.head()
.jsonp()
.patch()
These are called short cut methods. See bellow example using method .get()
Myapp.controller('serviceCtrl', function($scope,$http) { $http.get("tryit/angularjs/hello.html").then(function (responseData) { $scope.response = responseData.data; }); });
[/html]
In expandable format .get() can be written as given example:
Myapp.controller('serviceCtrl', function($scope,$http) { $http.get({ method: "GET", url: "tryit/angularjs/hello.html" }).then(function successRes(responseData) { $scope.response = responseData.data; }, function errorsRes(responseData) { $scope.response = responseData.data; } ); });
[/html]
In above example example, when defining two functions, first function is called if request was success and second function is called in case of error in request or to handle exception/error.
Note: Response comes from serve as an object. This object has given properties:
.status: This is a numeric value that defines the HTTP status.
.statusText: This is a string that defines the HTTP status.
.config: This is an object that is used to initiate the request.
.data : This can be a string or array returned from server.
.headers: .header is used to get header information.
A Noun is the name of a person, place or thing. or Name of anything is noun. For example: Sita…
Misko Hevery, a Google employee, developed AngularJS. First version 1.0 of AngularJS was released in 2012. Now AngularJS is fully…
AngularJS expressions contain operators,literals, and variables. AngularJS expressions can be written inside HTML while JavaScript expressions can't be. AngularJS expressions…
Some sentences are given below. Choose the nouns and mention the type of noun whether they are proper noun, common…
Modules are containers for appication controller. They contain different parts of an application. [html] {{ state + " " +…
Using Directives you can extend HTML attributes. In AngularJS you can define your own directives while it has its own…