I am handling many variable in my application, I dont want to define the string each and every time. Instead of that I want to access the string from one file and access through all the files in my application.
Eg:
one = 1;
I want to access 1 with the variable name one in my application, because in future it can be changed as one (one = one) that time I cant change in all the place.
In order to avoid such difficulty am going for the constant file.
You can create a service and access it in any controller by injecting it.
angular.module('app')
.constant('CONSTANTS', {something: 12});
your controller
angular.module('app').controller('mainCtrl', function (CONSTANTS) {
$scope.mainctrlvariable = CONSTANTS.something;
});
your another controller
angular.module('app').controller('otherCtrl', function (CONSTANTS) {
$scope.otherCtrlvariable = CONSTANTS.something;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With