srbhakta
srbhakta

Reputation: 75

How to make *ngFor work with an ObservableArray in Nativescript?

An ObservableArray works fine with <ListView [items]="feedsComments", where feedsComments is an ObservableArrayin NativeScript.

But when I replace the ListView with the following:

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

It throws the following error:

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

Upvotes: 0

Views: 752

Answers (1)

leoncc
leoncc

Reputation: 233

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

Ugly, but it works. Seems that the class can do with a getItems() method. There is a getItem(i) though to get a specific item in the array.

Upvotes: 1

Related Questions