It's all about
connecting the dots

AngularJS: Models and services

Reference: AngularJS in Action

Services are a way to define functionality that’s common to the entire application.

There are five types of services that you can define using the module convenience methods: module.constant, module.value, module.service, module.factory, and module.provider.

Communication with remote servers is facilitated with the $http service, which has shortcut methods built into it that mirror REST verbs.

The $http service is based on a deferred / promise API that provides mechanisms for you to handle asynchronous calls to the server.

Further control over asynchronous operations can be exerted (运用、发挥、施以影响) by using a deferred object returned by calling $q.deferred.

Calls made using $http can be intercepted by creating an interceptor ad pushing it into the $httpProvider.interceptors array during the module.config block.

Services can be enhanced by capturing them in a $provide.decorator call in the module.config block and modifying its behavior.

$httpBackend is great for mocking out server-side calls and defining the response.

Manually resolve a promise in a unit test by calling $rootScope.$digest.

赞(0) 打赏
版权声明:非商业用途转载请注明文章链接,商业用途转载请联系邮箱获取授权。
文章名称:《AngularJS: Models and services》
文章链接:https://www.orzzone.com/angularjs-models-and-services.html
商业联系:yakima.public@gmail.com
本站内容仅供个人学习交流,不做为任何投资、建议的参考依据,因此产生的问题需自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏