我有一项提供config
数据的服务。
@Injectable()
export class ConfigData {
someObj: any;
constructor(private http: HttpClient) {
this.http.get('/config-data').subscribe((data) => {this.someObj = data})
}
}
现在我想使用该对象在另一个服务中设置一个静态变量。
@Injectable()
export class AnotherService {
public static A_STATIC_VAR = ConfigData.someObj.specific_value
constructor(){}
}
如果我ConfigData
在构造函数中添加AnotherService
它是无用的,因为它没有及时将值分配给静态变量。当它们在其他地方使用时,它们已经“未定义”。
有没有办法做到这一点?