如何让* ngFor在Nativescript中使用ObservableArray?

时间:2017-11-16 12:05:41

标签: nativescript ngfor nativescript-angular

ObservableArray<ListView [items]="feedsComments"一起使用,其中feedsComments是NativeScript中的ObservableArray

但是当我用以下内容替换ListView时:

<StackLayout *ngFor="let item of feedsComments">
</StackLayout>

它会抛出以下错误:

ERROR Error: Cannot find a differ supporting object '[object Object],[object Object]' of type 'object'.
NgFor only supports binding to Iterables such as Arrays. 

1 个答案:

答案 0 :(得分:0)

<StackLayout *ngFor="let item of feedsComments._array" height="100" width="100">
    <Label [text]="item.someField"></Label> 
</StackLayout>

丑陋,但它确实有效。似乎该类可以使用getItems()方法。但是有一个getItem(i)来获取数组中的特定项。

相关问题