LoginSignup
2
3

More than 5 years have passed since last update.

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

Posted at
<p *ngFor="let item of items">{{item.name}}</p>

*ngForを使うと上記のようなエラーを返してくる。
そして{{item.name}}が何も返してくれない。


サーチするといろいろ、*ngForはArrayなどに使うのであってObjectには対応していないのだよ とかムツカシイお答えが多い。
対応方法も???なものばかり。


解決方法はズバリ


ビルトインPipeを使えばよい。

<p *ngFor="let item of items | async">{{item.name}}</p>



| asyncを追加。

これだけ。


こういうやり方もある

this.someCollection.valueChanges()
                    .subscribe((items) => this.items = items);

ObservableのvalueChanges()にitemsを登録する(subscribeする)だけ。


以上。

おつかれ → オレ

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3