Created
August 2, 2013 16:23
-
-
Save wesleycho/6141245 to your computer and use it in GitHub Desktop.
module.provider() example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp', []) | |
.provider('greeterProvider', function () { | |
var greeting = 'Hello!' | |
this.greeting = function (name) { | |
return 'Hello ' + name + '!'; | |
}); | |
function Greeter() { | |
this.greet = function () { | |
return greeting; | |
}; | |
} | |
this.$get = function () { | |
return new Greeter(); | |
}; | |
}) | |
.config(function (greeterProvider) { | |
greeterProvider.greeting('World'); | |
}); | |
In your controller, you can do this: | |
function MyCtrl(greeter) { | |
$scope.greet = greeter.greet(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment