我有一个带有全局变量的文件:
@Injectable()
export class Globals {
public baseURL:string;
public loginURL:string;
public proxyURL:string;
public servicesURL:string;
constructor(platformLocation: PlatformLocation) {
this.baseURL = (platformLocation as any).location.href;
this.loginURL = this.baseURL + 'rest/login';
this.proxyURL = this.baseURL + 'rest/proxy';
this.servicesURL = this.baseURL + 'rest/serviceRegistry';
}
}目前,我的API调用失败了,因为还没有设置变量。是否有一种方法只在构造函数运行时注入此服务,还是必须使用可观察的?
发布于 2018-05-04 06:54:57
它本身并没有解决。我现在就这样用它:
@Injectable()
export class Globals {
/** API URLS */
public baseURL:string = '';
public loginURL:string = 'rest/login';
public proxyURL:string = 'rest/proxy';
public servicesURL:string = 'rest/serviceRegistry';
}https://stackoverflow.com/questions/49387039
复制相似问题