Var myapp = angular.module ("myApp", []);// controller referenced in provider factory service , you don't need to add a suffix ... Myapp.controller ("Mycontroller", Function ($scope, my,myfactory,myservice) { $scope. hellos = [ my.sayhello (), myfactory.sayhello (), myservice.sayhello () ]}); Myapp.service ("MyService", function () { // Note this Objects this.sayHello = function () { return "Hello world for service"; });// Note Note Using the $get method 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; });// Note Return// var xxx = {} ;// return xxx; myapp.factory ("MyFactory", function () { return{ sayhello : function () { return "Hello world for factory "; } });// for provider must be added "provider" suffix myapp.config (function (MyProvider) { Myprovider.setname ("World");})
Angluar distinguishes Service/factory/provider's "Hello World" version