你的位置:首页 > 软件开发 > Java > Part 18 $http service in AngularJS

Part 18 $http service in AngularJS

发布时间:2016-04-24 02:00:19
In Angular there are several built in services. $http service is one of them. In this video, we will discuss another built in service, $log. ...

In Angular there are several built in services. $http service is one of them. In this video, we will discuss another built in service, $log. It is also possible to create our own custom services in Angular. At this point several questions come to our mind

  • What are services in Angular
  • When should we be creating services in Angular
  • How to create our own custom Angular services
  • Where do they fit, in an angular application architecture
  • What are the benefits of using services

I will answer all these questions in a later video. The reason for postponing this discussion, is that, it is easier to understand the concept of Angular services and the benefits they provide, once we understand how to use use 1 or 2 built in angular services. So, let's start our discussion with $http service. $http service in Angular is used to make HTTP requests to remote server $http service is a function that has a single input parameter i.e a configuration object. Example : The following example issues a GET request to the specified URL 

$http({Shortcut methods like get, post, put, delete etc are also available to be used with $http serviceExample : Using the short cut method get()$http service returns a promise object. This means the functions are executed asynchronously and the data that these functions return may not be available immediately. Because of this reason you cannot use the return value of the $http service as shown below.$scope.employees = $http.get('EmployeeService.asmx/GetAllEmployees');Instead you will use the then() method. The successCallback function that is passed as the parameter to the then function is called when the request completes. The successCallback function receives a single object that contains several properties. Use the data property of the object to retrieve the data received from the server.

$scope.employees = $http.get('EmployeeService.asmx/GetAllEmployees')

$scope.employees = $http.get('EmployeeService.asmx/GetAllEmployees')

$scope.employees = $http.get('EmployeeService.asmx/GetAllEmployee')

$scope.employees = $http.get('EmployeeService.asmx/GetAllEmployee')

var successCallBack = function (response) {

原标题:Part 18 $http service in AngularJS

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。