无法将常量注入另一个模块配置

时间:2016-09-06 11:32:16

标签: javascript angularjs

问题是我无法从一个模块到另一个模块配置插入常量。

主要应用:

'use strict';

angular.module('identicaApp', [
    'ngRoute',
    'identicaApp.common',
    'identicaApp.mainPage',
    'identicaApp.aboutPage',
    'identicaApp.registerPlayer'
]).config(['$locationProvider', '$routeProvider', function ($locationProvider, $routeProvider) {
    $locationProvider.hashPrefix('!');

    $routeProvider.otherwise({redirectTo: '/main'});
}]);

common.js:

angular.module('identicaApp.common', [])
  .constant('ROOT_PATH', '/static/angular/identica/');

和问题模块:

'use strict';

angular.module('identicaApp.mainPage', [
    'ngRoute',
    'identicaApp.common'
])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/main', {
    templateUrl: common.ROOT_PATH + 'main_page/main_page.html',
    controller: 'MainPageCtrl'
  });
}])

.controller('MainPageCtrl', [function() {

}]);
加载程序无法看到

common.ROOT_PATH ...

2 个答案:

答案 0 :(得分:0)

我认为您错过了向 string tableName = string.empty if(source == "a") tableName =db.GetTable("aTable"); if(source == "b") tableName=db.GetTable("bTable"); and then query like.. tableName.where() 调用注入实际常量(例如,将服务注入控制器的方式),然后您必须通过它的名称引用它:

config

答案 1 :(得分:0)

你需要包含常量并像这样使用它:

getResources()

如果你想在.config(['$routeProvider', function($routeProvider, ROOT_PATH) { $routeProvider.when('/main', { templateUrl: ROOT_PATH + 'main_page/main_page.html', controller: 'MainPageCtrl' }); }]) 下有多个常量“变量”,请按照这样做。

ROOT_PATH

然后你可以这样使用它:

angular.module('identicaApp.common')
  .constant('ROOT_PATH', {
    'URL': '/static/angular/identica/',
    'NAME': 'Test',
    'ANOTHER_THING': 'Something'
});
相关问题