Answers for "create and use constants in angularjs"

0

create and use constants in angularjs

// Storing a single constant value
var app = angular.module('myApp', []);

app.constant('appName', 'My App');

// Now we inject our constant value into a test controller
app.controller('TestCtrl', ['appName', function TestCtrl(appName) {
    console.log(appName);
}]);

// Storing multiple constant values inside of an object
// Note: values in the object mean they can be modified
var app = angular.module('myApp', []);

app.constant('config', {
    appName: 'My App',
    appVersion: 1.0,
    apiUrl: 'http://www.facebook.com?api'
});

// Now we inject our constant value into a test controller
app.controller('TestCtrl', ['config', function TestCtrl(config) {
    console.log(config);
    console.log('App Name', config.appName);
    console.log('App Name', config.appVersion);
}]);
Posted by: Guest on June-13-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language