0
可以根据环境定义静态变量吗?Angular 2:根据环境定义静态变量
喜欢的东西(此代码是一个愚蠢的例子,但它拥有的想法):
if (environment.production) {
public static MY_VAR: string = 'A';
} else {
public static MY_VAR: string = 'B';
}
感谢您的咨询!
可以根据环境定义静态变量吗?Angular 2:根据环境定义静态变量
喜欢的东西(此代码是一个愚蠢的例子,但它拥有的想法):
if (environment.production) {
public static MY_VAR: string = 'A';
} else {
public static MY_VAR: string = 'B';
}
感谢您的咨询!
当我第一次启动应用程序,然后根据dev,qa和uat url设置我的应用程序中的api端点时,我所做的是从window.location.host中读取url。 如何做到这一点?
在main.ts文件
platformBrowserDynamic([{provide:'EndPoint',useValue:config.getEndPoint()}])
export class config{
public static getEndPoint(){
const host = window.location.host
if(host) // your logic goes here{
}
}
}
在服务注入像
constructor(@Inject('EndPoint') private endPoint:string)
'公共静态MY_VAR = environment.production? 'A':'B'? –
谢谢你的解决方案! –