当我提出GET
请求并得到消息时,500 ошибку
我无法接受此错误并对其进行处理,以免出现此类错误console
如何获取并处理它以显示用户的消息它在哪里?
P.s 无法创建标签
index.component.html
<tbody *ngFor="let item of category">
<tr>
<td>{{item.id}}</td>
<td>{{item.translation[0].name}}</td>
<td>{{item.status}}</td>
</tr>
</tbody>
index.component.ts
ngOnInit() {
this.paginDiss = 1;
this.four = 4;
this.pagination = [];
this.fullPagination = [];
this.restDataService.getData('category').subscribe((items) => {
this.category = items['data'];
});
}
服务.ts
constructor(private http: HttpClient, private router: Router) {
}
getData(dataUrl) {
const url = `${environment.endpoint}${dataUrl}`;
const header = new HttpHeaders()
return this.http.get(url, {
headers: header
})
}
见这里https://angular.io/guide/http#error-handling