gpt4 book ai didi

javascript - angularjs 在服务中包含另一个模块

转载 作者:行者123 更新时间:2023-12-03 08:39:55 25 4
gpt4 key购买 nike

我想在我的服务中包含另一个模块,我有一些相关的常量/配置。我的配置模块如下所示:

angular.module('myApp.config', [])
.constant('EnvironmentConfig', {
"WindowsAzureADConfig": {
"tenant": "aaa.onmicrosoft.com",
"clientAppId": "xx-xx-xx-xx-xx",
"authority": "https://login.windows.net/aa.onmicrosoft.com",
"resourceUrl": "https://graph.windows.net/",
"redirectUrl": "http://localhost:4400/services/aad/redirectTarget.html"
},
"AppEndPointConfig": {
"tokenAccess": "aa-aa-a-a-aa",
"baseURL": "http://aa.aaa.aa/api/",
"paths": {
"bpath": "bpath/"
}
},
"PConfig": {
"ApiKey": "aaadd2dasdasdas23f44ffsfsdf",
"printerId": 244312
}
}
);

我有以下 angularjs 服务:

(function () {
function MySrv(EnvironmentConfig) {
var mySrv = {};
var app = {
aFunction: function () {
console.log(EnvironmentConfig.authority); // getting undefined
}
};
mySrv.app = app;

return mySrv;
}

angular
.module('myApp') // if adding .module('myApp', ['myApp.config']) then I'm getting a blank screen
.service('MySrv', mySrv);
})();

请注意,该模块是在服务本身之前包含和定义的。

最佳答案

你不能重新声明一个模块,当你这样做时你会这样做

.module('myApp', ['myApp.config'])

正如 Gustav 所说,您要么将 myApp.config 包含在您第一次声明 myApp 的位置,要么将您的服务放入其自己的模块中,就像您对 myApp.config 所做的那样。

.module('myApp.service', ['myApp.config'])

但是您需要将服务模块包含到您的 myApp 模块中。像这样:

.module('myApp', ['myApp.service'])

由于服务模块包含配置模块,因此不需要将其包含在 myApp 模块中

关于javascript - angularjs 在服务中包含另一个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33076403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com