Thursday, 21 April 2016

Constant in angular:


A constant can be injected everywhere. A constant can not be intercepted by a decorator, that means that the value of a constant should never be changed (though it is still possible to change it programmatically in Angular 1.x).

Syntax:
.constant(name, value);

name --> name of constant
value --> value of constant

Example:

var myAppangular.module('myApp', []);

myApp.constant("clientId", "123456");

myApp.config(['clientId', function(clientId){
console.log(clientId);
}])

myApp.controller('myController',['clientId', function(clientId){
console.log(clientId);
}])

so, the difference between constant and value is constant inject in  config block but value can't

No comments:

Post a Comment