如何在下面的代码和 environment.ts
文件中设置条件。
export const environment = {
production: true,
if(our condiion = "impdev.something.com"){
API_url:'https://impdev.something.com/Angular',
}
if(our condiion = "dev.something.com"){
API_url:'https://dev.something.com/Angular',
}
if(our condiion = "app.something.com"){
API_url:'https://app.something.com/Angular',
}
};
最佳答案
您将使用以下解决方案以其他方式实现此目的。
环境.ts
export const environment = {
production: true,
dev: { serviceUrl: 'https://dev.something.com' },
stage: { serviceUrl: 'https://stage.something.com' },
prod: { serviceUrl: 'https://prod.something.com' },
local: { serviceUrl: 'http://localhost:8080/' },
};
NetworkService.ts
export class NetowrkService {
url: string;
env: string
constructor(private http: HttpClient) {
this.env = this.setENV();
this.url = environment[this.env].serviceUrl;
}
setENV() {
if (window.location.hostname.indexOf("dev") != -1) {
return "dev";
} else if (window.location.hostname.indexOf("stage") != -1) {
return "stage";
} else if (window.location.hostname.indexOf("localhost") != -1) {
return "local";
} else {
return "prod";
}
}
// Call rest API
}
关于php - 在environment.prod.ts 文件上设置条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54362003/