Tuesday, 23 June 2015

angular module again



angular.module("app",[])."we will discuss what we can append after this."

in another word, what functions we can call, or what we can attache to the app?

You may know:

controller,
provider,
service,
factory,
filter,
directive


you may not know:

value,
constants

You can create them and inject them into controller and services and use them directly.


Value:


var myApp = angular.module('myApp', []);
myApp.value('clientId', 'a12345654321x');

myApp.controller('DemoController', ['clientId', function DemoController(clientId) {
  this.clientId = clientId;
}]);




Constants:


myApp.constant('planetName', 'Greasy Giant');
We could then configure the unicornLauncherProvider like this:
myApp.config(['unicornLauncherProvider', 'planetName', function(unicornLauncherProvider, planetName) {
  unicornLauncherProvider.useTinfoilShielding(true);
  unicornLauncherProvider.stampText(planetName);
}]);
And since Constant recipe makes the value also available at runtime just like the Value recipe, we can also use it in our controller and template:
myApp.controller('DemoController', ["clientId", "planetName", function DemoController(clientId, planetName) {
  this.clientId = clientId;
  this.planetName = planetName;
}]);




https://docs.angularjs.org/guide/providers









No comments:

Post a comment