我想使用可以在项目中的任何位置调用的常量变量。不能将常量注入其他模块angularjs ionic
我做了'constants.js'。
angular.module('myApp.constants', [])
.constant('const', (function(){
return {
username = 'abc'
}
})()
);
'app.js'
angular.module('myApp', ['ionic', 'myApp.controllers', 'myApp.constants'])
.run(function($ionicPlatform, $rootScope) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
'controllers.js'
angular.module('myApp.controllers', [])
.controller('LoginCtrl', function($scope, $ionicPopup, $http, $state, const) {
$scope.user_name = const.username;
});
当我打电话从控制器 '常量',我得到这个错误。
D/SystemWebChromeClient: file:///android_asset/www/js/controllers.js: Line 8 : Uncaught SyntaxError: Unexpected token const
I/chromium: [INFO:CONSOLE(8)] "Uncaught SyntaxError: Unexpected token const", source: file:///android_asset/www/js/controllers.js
我不熟悉angularjs及其模块。 我希望有人能把我送到正确的方向。
在此先感谢。
它不工作:( – Thwe