【发布时间】:2017-10-04 19:18:31
【问题描述】:
在我的 Angular 应用程序服务中,我有一个调用模拟 JSON 的方法:
我的.service.ts:
...
private baseUrl: string = 'http://localhost:9999/accounts-grid.json';
...
loadAccounts() {
if (this.dataStore.responseObject) {
this.refreshDataStore();
}
let token = this.authenticationService.getToken();
let headers = new Headers({ 'netx.esf.AuthenticationService': token });
let options = new RequestOptions({ headers: headers });
this.http.get(`${this.baseUrl}/positions/priorday/${accountNumber}`, options)
this.http.get(`${this.baseUrl}`, options)
.map((response: Response) => response.json())
.subscribe(
...
error => {
this.logService.error('loadAccountList() exception:', error);
this.setError(this.message[0], error._body); });
return this.responseObject$;
}
我希望能够使用相同的调用加载不同的虚拟 JSON,具体取决于调用该方法的次数。例如,第一次调用 loadAccounts() 时,我想从 accounts-grid.json 获得响应,第二次调用时,我想从 accounts2-grid.json 获得响应。
这可能吗?
【问题讨论】:
标签: javascript json angular