$provide对象的provider、factory、service方法
Last updated
Last updated
<div ng-app="myApp">
<div ng-controller="firstController">
{{name}}
</div>
</div>
<script src="//cdn.bootcss.com/angular.js/1.4.8/angular.js"></script>
<script type="text/javascript" src="app/index.js"></script>var myApp = angular.module('myApp',[],function($provide){
// 自定义服务
$provide.provider('CustomService',function(){
this.$get = function(){
return {
message : 'CustomService Message'
}
}
});
// 自定义工厂
$provide.factory('CustomFactory',function(){
return [1,2,3,4,5,6,7];
});
// 自定义服务
$provide.service('CustomService2',function(){
return {
message : 'CustomService Message2'
}
})
});
myApp.controller('firstController',function($scope, CustomFactory, CustomService, CustomService2){
$scope.name = '张三';
console.log(CustomFactory);
console.log(CustomService);
console.log(CustomService2);
});var app = angular.module('myApp', []);
app.service();
app.factory();