我将用管道解析一个 ID。
我认为这不是每次调用服务/api的最佳方式吗?
之前存储所有国家会更好吗?我怎样才能在管道中返回国家名称?
服务:
getCountry(id:number) {
return this._http.get(this.apiUrl + "/country/" + id).map(res => res.json());
}
管道:
export class ResolvePipe implements PipeTransform {
constructor(public _formDataService: FormDataService) {}
transform(value: number, args: any[]): any {
this._formDataService.getCountry(value).subscribe(
data => console.log(data[0].name)
)
}
}
编辑:
<tr (click)="showProfile(customer)" *ngFor="let customer of (customers | search:term)">
<td>...</td><td>{{customer.country_id | resolve | async}}</td>
</tr>