var myApp = angular.module("myApp",[]);// controller 中引用 provider factory service 的时候,不需要添加后缀。。。myApp.controller("myController",function($scope,my,myFactory,myService){ $scope.hellos = [ my.sayHello(), myFactory.sayHello(), myService.sayHello() ]});myApp.service("myService",function(){ // 注意this 对象 this.sayHello = function () { return "hello world for service"; }});// 注意 注意使用$get 方法 myApp.provider("my", function () { this.name = "default"; this.$get = function () { var name = this.name; return { sayHello: function () { return "hello " + name+ " for provider" ; } } } this.setName = function(name){ this.name = name; }});// 注意 return// var xxx = {} ;// return xxx; myApp.factory("myFactory", function () { return{ sayHello: function () { return "hello world for factory"; } }});// 对于 provider 必须添加 "provider"后缀myApp.config(function (myProvider) { myProvider.setName("world");})