Last active
September 17, 2015 06:42
-
-
Save yngvebn/442b4da1f559f222dae6 to your computer and use it in GitHub Desktop.
This file contains 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.controller('Test', function(MyProvider, MyService, MyFactory){ | |
// returnerer akkurat det samme: | |
MyProvider.sayHello(); | |
MyService.sayHello(); | |
MyFactory.sayHello(); | |
MyProvider.saySomethingElse(); // 'I might be a string from some configuration or whatevs' | |
}); | |
angular.config(function(MyProviderProvider){ | |
MyProviderProvider.configureWhatElseToSay ('I might be a string from some configuration or whatevs') | |
}); | |
angular.provider('MyProvider', function(){ | |
var data = { | |
whatElseToSay = ''; | |
} | |
// can be called from angular.config | |
this.configureWhatElseToSay = function(whatToSay){ | |
data.whatElseToSay = whatToSay; | |
} | |
function saySomethingElse(){ | |
return data.whatElseToSay; | |
} | |
function sayHello(){ | |
return 'Hello!'; | |
} | |
function sayGoodbye(){ | |
return 'Buhbye!'; | |
} | |
// only stuff exposed by calling $get will be available in application runtime | |
this.$get = function(){ | |
return { | |
sayHello: sayHello, | |
sayGoodbye: sayGoodbye, | |
saySomethingElse: saySomethingElse | |
} | |
} | |
}); | |
angular.service('MyService', function(){ | |
// only stuff on 'this.' will be exposed at runtime | |
this.sayHello = sayHello; | |
this.sayGoodbye = sayGoodbye; | |
function sayHello(){ | |
return 'Hello!'; | |
} | |
function sayGoodbye(){ | |
return 'Buhbye!'; | |
} | |
}); | |
angular.factory('MyFactory', function(){ | |
function sayHello(){ | |
return 'Hello!'; | |
} | |
function sayGoodbye(){ | |
return 'Buhbye!'; | |
} | |
// only stuff returned will be exposed at runtime | |
return { | |
sayHello: sayHello, | |
sayGoodbye: sayGoodbye | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment