【发布时间】:2018-10-01 05:54:16
【问题描述】:
如何显示错误信息。
如果搜索结果在 Angular 中没有匹配值。
例如:如果未找到搜索结果,那么我想显示一些消息,例如未找到结果。
listuser.component.html
<input #searchBox ng-model="searchText" id="searchBox" placeholder="search by id" (keyup)="searchUser(searchBox.value) ">
<table class="table table-striped">
<thead>
<th>Id</th>
<th>User Name</th>
</thead>
<tbody>
<tr *ngFor="let user of users">
<td>{{user.id}}</td>
<td>{{user.username}}</td>
</tr>
</tbody>
</table>
listuser.component.ts
searchUser(id){
var temp = [];
this.users = [];
this._userService.getUser(id).subscribe((temp) => {
console.log(temp)
this.users.push(temp);
console.log(this.users)
}, (error) => {
console.log(error);
})
}
这是我的 user.service.ts
getUser(id: Number){
return this._http.get(this.baseUrl + '/car/' + id, this.options)
.map((response: Response) => response.json())
.catch(this.errorHandler);
}
【问题讨论】:
标签: angular spring-boot