1
這裏是client.service.ts角2:無法找到一個支持不同對象* ngFor
clients: Client[];
getClientList()
{
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let authToken = localStorage.getItem('auth_token');
console.log(authToken);
headers.append('X-auth-Token', authToken)
return this._http.get('http://localhost:8080/api/v1/client/list?isClient=Y', {headers})
.map((data: Response) => {
this.clients= JSON.parse(data['_body']);
return this.clients;
})
}
我已經創建模型的客戶端。
HomeComponent.ts
onTestGet()
{
this._httpService.getClientList()
.subscribe(
data => this.getData = JSON.stringify(data),
error => alert(error),
() => console.log("finished")
);
}
home.html的
<select class="borderdiv" #select [(ngModel)]="cuurent" (change)="onChange($event.target.value)" class="form-control input-group" *ngIf="radioValue == 'yes'">
<option *ngFor="let client of getData"> {{client.clientName}} </option>
</select>
響應數據:
[{"userId":"cos.com","clientCode":"75","clientName":"Abc COMPANY, THE"},{"userId":"maintenance.com","clientCode":"51","clientName":"AINC./ ALSTYLE APPAREL"}]
我尋覓了lot.but無法解決問題。請幫幫我。
顯然'getData'沒有返回您顯示爲'響應data'數組。嘗試'
請發佈代碼爲'getClientList()' –
我試過{{getData | json}},在html中獲得響應 –