【发布时间】:2016-09-15 18:33:12
【问题描述】:
我是 Angular2 的新手。我正在寻找在我的 Angular 2 应用程序中访问 Windows 环境变量的方法。我有一个 env.js 文件,它的 URL 如下。-
(function (window) {
window.__env = window.__env || {};
window.__env.previewUrl = 'http://localhost:3000/';
window.__env.workflowUrl = 'http://localhost:1337';
window.__env.baseUrl = '/';
}(this));
我需要在我的 angular 2 组件中访问 this 变量,但它给出了类型窗口上不存在 _env 的错误。
this._http.get( window.__env.workflowUrl + this.swaggerDefSplit[1] + queryString1)
.map(res => res.json())
.subscribe(data => {
console.log(data);
if (!(data.Results instanceof Array)) {
// puts a single json object into array for *ngFor
data.Results = JSON.parse(JSON.stringify([data.Results]));
}
感谢您的帮助。
【问题讨论】:
标签: angular