Я вызываю эту 2 функцию this.fetchTables ();this.fetchAllTables ();в конструкторе файла demo.ts в Angular.
Оба получают вызов 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);
}
});
}