立诚勿怠,格物致知
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

本站大部分文章为原创或编译而来,对于本站版权文章,未经许可不得用于商业目的,非商业性转载请以链接形式标注原文出处。
本站内容仅供个人学习交流,不做为任何投资、建议的参考依据,因此产生的问题需自行承担。

评论 抢沙发

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

非常感谢你的打赏,我们将继续给力提供更多优质内容!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册