2
我得到這個代碼AppComponent:無法讀取屬性 '名' 空的Angular2 JSON
getPlanetsToView(page){
let pageToView = page*10 + 10;
for(var i=0; i<pageToView; i++){
this.planetsToView.push(this.planets.planets[i]);
}
}
ngOnInit() {
this.http.get('app/planets.json').subscribe(res => {
this.planets = res.json();
console.log(this.planets);
this.getPlanetsToView(0);
});
而且我有這個模板:
{{planetsToView[0].name | json}}
我有問題: Photo
當我嘗試{{planetsToView [0] | json}}它可以工作,但也包含其他屬性。
當我做到了,我得到了錯誤: main.browser.ts:10錯誤:模板解析錯誤:(...) –
我不知道是錯誤,但是當我把它抄了,開始工作。謝謝! –