function module configuration angularJS

p r O v i d e set Righteousness provide defined services provider
service itself is an arbitrary object
ng involves providing service to its dependency injection mechanism
angular with p r o v i d e r , p r o v i d e r provider objects automatic dependency injection mechanism, by calling the injection mechanism is a provider of 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...
}):

p r o v i d e . p r o v i d e r provide.provider** ** 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......){
//函数内参数先后顺序随便排列
}):

Guess you like

Origin blog.csdn.net/qq_44858021/article/details/91896546