如何改变angualar.module常量配置字段?

时间:2017-05-23 19:29:47

标签: angularjs

我想将dashboardApi的值从http://devdashboard.company.com/'更改为../api(相对于一级文件夹的相对路径),我尝试../api但不是&# 39;工作,如何解决?

'use strict';

angular.module('configuration', [])
    .constant('config', {
        dashboardApi : 'http://devdashboard.company.com/',
        authApi: 'http://urlink.company.com/',
        debug: false,
        firstName: '',
        lastName: '',
        userid: '',
        employeeid: '',
        qGroups: [""],
        role : '',
    });

1 个答案:

答案 0 :(得分:0)

无论您想要更改它,都可以在主角度模块的所需config内注入component依赖项。

//make sure configuration module have been injected in main app module.
angular.module('app', ['configuration']);

//here I took an example of config block of your application.
//because generally such setting should be set at configuration time of app.
//the same inject you can do it other component as well, like controller, directive, factory, etc.
angular.module('app').config(['config', function(config){
   config.dashboardApi = '../api.'
})