【发布时间】:2018-10-05 22:05:14
【问题描述】:
我正在使用 Angular 6,我正在尝试检查 _appconfig.json 文件是否存在于根目录中。如果该文件不存在,我想将 http.get() 调用指向另一个 URL。不过,我似乎无法让事情表现得像我想要的那样,并且想知道是否有人可以在这里帮助我。
如果所述文件不存在,我该怎么更改 URL?
configUrl = "_appconfig.json";
constructor(private http: HttpClient) {}
data: any;
getConfig(): Promise<configType> {
return this.http
.get(this.configUrl)
.toPromise()
.then(response => response as configType)
.catch(this.handleError);
}
对于它的价值,如果文件确实存在,这将按预期运行。
【问题讨论】:
标签: angular typescript promise httpclient