環境値を指定できる構成サービスを作成しようとしています。これを使用して、適切な構成値を吐き出します。
このようなもの
import { Injectable } from '@angular/core';
@Injectable()
export class ConfigService {
private env: string;
SetEnv(value: string) {
this.env = value;
}
Get() {
let rtrn;
if (this.env == "DEV") {
rtrn = {
api: "http://localhost:60517/api/"
}
}
else if (this.env == "TEST") {
rtrn = {
api: "http://test:60517/api/"
}
}
else { }
return (rtrn);
}
}
これに続いてapp.module.ts
providers: [
ConfigService.SetEnv("DEV"),
....
]
そして、コンポーネントに注入された後、次のように使用されます
ConfigService.Get().api
上記の例では、次のエラーがスローされます。app.module.ts:64 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_12__services_config_config_service__.a.SetEnv is not a function
それらの線に沿った何か...しかし、これを達成するための他の提案を歓迎します。