标签:png name color function 注入 return this http factory
服务本身是一个任意的对象,ng提供的服务过程涉及它的依赖注入机制。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div ng-app="myApp"> <div ng-controller="firstController"> {{name}} </div> </div> <script type="text/javascript" src="../../vendor/angular/angularjs.js"></script> <script type="text/javascript" src="app/index.js"></script> </body> </html>
var myApp = angular.module(‘myApp‘,[],function ($provide) { //自定义服务 $provide.provider(‘CustomService‘,function () { this.$get = function () { return{ message : ‘CustomService Message‘ } } }) }); myApp.controller(‘firstController‘,function ($scope,CustomService) { $scope.name = ‘Alrale‘; console.log(CustomService); });
Angularjs[13] - 定义服务 $provide 中 provider 方法
标签:png name color function 注入 return this http factory
原文地址:http://www.cnblogs.com/bky-1083/p/6352277.html