1
好吧,我有一個問題,很多人似乎有問題,但沒有一個解決方案在stackoverflow或GitHub似乎有所幫助。例外:在[AppWidgetsComponent @ 8:28中的應用程序]中找不到不同的支持對象'storeApps'
我得到一個錯誤:
EXCEPTION: Cannot find a differ supporting object 'storeApps' in [apps in [email protected]:28]
我相信正在引起由ngFor:
<div class="container app-widgets">
<div class="row">
<div class="col-sm-10 col-sm-offet-1">
<div class="container">
<div class="row">
<ul>
<li *ngFor="#widget of apps"></li>
</ul>
</div>
</div>
</div>
</div>
</div>
對應分量定義爲:
import { Component, Input } from 'angular2/core';
import { NgFor } from 'angular2/common';
import { AppWidgetComponent } from '../appwidget/appwidget.component';
import { StoreApp } from '../../models';
@Component({
selector: 'app-widgets',
template: require('./appwidgets.component.html'),
styles: [require('../../../sass/appwidgets.scss').toString()],
directives: [AppWidgetComponent]
})
export class AppWidgetsComponent {
@Input() apps: Array<StoreApp>;
}
,我使用app-widgets
這樣的組件:
<app-widgets apps=storeApps></app-widgets>
我在相應的組件定義設置storeApps
:
@Component({
selector: 'home',
template: require('./home.component.html'),
styles: [require('../../../sass/home.scss').toString()],
directives: [AppWidgetsComponent, RecommendedRecentComponent]
})
export class HomeComponent {
private storeApps: Array<StoreApp>;
constructor(private _appsService: AppsService) {
}
recentSelected() {
this._appsService.getRecentApps()
.subscribe(
storeApps => {
this.storeApps = storeApps;
this.storeApps.forEach(element => {
console.log(JSON.stringify(element));
console.log();
})
},
(error: any) => AppComponent.generalError(error.status)
);
}
}
的AppService.getRecentApps()
方法是這樣的:
public getRecentApps() {
return this.http.get(`${appSettings.apiRoot}resources/recent`)
.map(res => <StoreApp[]> res.json().data)
.catch(this.handleError);
}
出現令我百思不解的是,爲什麼它在抱怨storeApps
,在應用程序組件中,而不是出現在app-widgets
組件中的apps
。
任何想法的人?
其實我不認爲「是速記」是真實的。 'app-widgets apps = storeApps> app-widgets>'只傳遞給瀏覽器以添加到DOM,而 app-小部件>'是由Angular處理的模板綁定。誠然,結果是一樣的,但我不會說這是一個速記。 –
@GünterZöchbauer更新了答案。謝謝(; – Sasxa
我現在不在,目前無法測試你的建議,但是會在幾個星期的幾個小時內這樣做,非常感謝。 – serlingpa