我要一步一步往上爬,等待阳光静静看着它的脸
小小的天有大大的梦想,重重的壳裹着轻轻地仰望

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
分享到: 更多 (0)

评论 抢沙发

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

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

支付宝扫一扫打赏

微信扫一扫打赏