【发布时间】:2018-12-21 07:33:28
【问题描述】:
我正在调用这 2 个函数 this.fetchTables(); this.fetchAllTables();在 Angular 中 demo.ts 文件的构造函数中。
两者都是获取 api 调用。在这两个电话中,每次都有 1 个电话失败。有时我会得到 fetchTables 的结果。有时我会得到 fetchallTables 的结果。
constructor(private api:BackendApiService, private spinner: NgxSpinnerService, private utills:CommonUtillsService, private router: Router) {
// reload or refresh page on active click
this.router.routeReuseStrategy.shouldReuseRoute = function() { return false; };
this.fetchTables();
this.fetchAllTables();
}
fetchTables() {
this.api.getTableAccess().subscribe(data => {
this.spinner.hide();
console.log('Data to get tables', data);
if(data) {
this.data = data.body.entities;
this.showNoTableRecordList = false;
}
},
(err: HttpErrorResponse) => {
if (err.status == 401) {
window.location.href = Constants.GANDALF_HOST;
}
this.spinner.hide();
if (err.error instanceof Error) {
//A client-side or network error occurred.
toast(Constants.TOAST_PREFIX+Constants.SOMETHING_WRONG, Constants.TOAST_DURATION);
} else {
//Backend returns unsuccessful response codes such as 404, 500 etc.
toast(Constants.TOAST_PREFIX+Constants.SOMETHING_WRONG, Constants.TOAST_DURATION);
}
});
}
fetchAllTables() {
this.api.getAllTable().subscribe(data => {
this.spinner.hide();
if(data) {
this.allTables = data.body;
this.showNoTableRecordList = false;
} else {
this.showNoTableRecordList = true;
}
},
(err: HttpErrorResponse) => {
if (err.status == 401) {
window.location.href = Constants.GANDALF_HOST;
}
this.spinner.hide();
if (err.error instanceof Error) {
//A client-side or network error occurred.
toast(Constants.TOAST_PREFIX+Constants.SOMETHING_WRONG, Constants.TOAST_DURATION);
} else {
//Backend returns unsuccessful response codes such as 404, 500 etc.
toast(Constants.TOAST_PREFIX+Constants.SOMETHING_WRONG, Constants.TOAST_DURATION);
}
});
}
【问题讨论】:
-
您能否分享有关失败的更多信息...这两个函数的错误对象返回什么?
标签: angular angular2-routing angular2-services