3
我有一類名爲條件:Angular2屬性不上鍵入 '任何[]'(JSON)存在
export class Condition{
name: string;
date: string;
link: string;
}
和一個函數命名搜索,使得HTTP GET請求:
public search(params: string): Observable<json[]> {
let queryString = this.serverUrl + params;
return this.http.get(queryString)
.map((res:Response) => res.json())
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
然後我得到一個對象來獲取具有特定屬性的條件。它有絕對的對象在陣列中的進入屬性:
this.search(`Condition?patient=Patient/107795`).subscribe(data => {
var conditionArray = data.entry; // data.entry is absolutely an ARRAY
for(var condition of conditionArray){
conditions.push({ //conditions is a Condition[]
name: condition.resource.code.coding[0].display,
date: condition.resource.dateRecorded,
link: "condition/" + condition.resource.id
});
}
} , err => { console.log(err); });
之前,我與啓動腳本寫這些代碼我開始這些項目:
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
該項目已於工作,我在控制檯上想要並且沒有錯誤。然而,當我停止它,並開始劇本再次啓動時,它給這個錯誤:
error TS2339: Property 'entry' does not exist on type 'any[]'.
你知道什麼是錯的,我該如何解決?
是的,我忘了改變它的類型。它正在工作,謝謝! –