Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ujasur
Forked from davertron/gist:5df8861b696443828bcf
Created August 19, 2014 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ujasur/fc33b7777839c5017466 to your computer and use it in GitHub Desktop.
Save ujasur/fc33b7777839c5017466 to your computer and use it in GitHub Desktop.
var myApp = angular.module('myApp', []);
myApp.provider('helloWorld', function() {
// In the provider function, you cannot inject any
// service or factory. This can only be done at the
// "$get" method.
this.name = 'Default';
this.$get = function() {
var name = this.name;
return {
sayHello: function() {
return "Hello, " + name + "!"
}
}
};
this.setName = function(name) {
this.name = name;
};
});
//hey, we can configure a provider!
myApp.config(function(helloWorldProvider){
helloWorldProvider.setName('World');
});
function MyCtrl($scope, helloWorld, helloWorldFromFactory, helloWorldFromService) {
$scope.hellos = [
helloWorld.sayHello(),
helloWorldFromFactory.sayHello(),
helloWorldFromService.sayHello()];
}​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment