📜  在 angularjs 中创建和使用常量 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:24.379000             🧑  作者: Mango

代码示例1
// 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);
}]);