provider
service itself is an arbitrary object
ng involves providing service to its dependency injection mechanism
angular with
get () method, the obtained object as a parameter-related calls
example creating module:
var myApp=angular.module('myApp',[],function(){
//此函数称为模块配置,即在模块启动时自动执行,
//也可自定义服务
//$provide.provider...
//$provide.factory...
//$provide.service...
}):
provide.factory
$provide.service
$provide.provider('name',function(){
this.$get=function(){
return value
//返回的内容只能是对象
}
}):
$provide.factory('name',function(){
return value;
//返回的内容可以是任何类型
});
$provide.service('name',function(){
return value;
//返回的内容只能是对象(数组也是对象),即不能是基本类型,只能是引用类型
});
These services are also simple wording:
angular.factory('name',function(){})
angular.service('name',function(){})
After creating the service, you can call as related in the controller:
angular.module('myApp',[]).controller('myCtrl',function($scope,自定义服务1,自定义服务2......){
//函数内参数先后顺序随便排列
}):