【发布时间】:2020-08-27 17:03:54
【问题描述】:
我还没有调用这些值的服务,所以我正在使用 aysnc ngFors 做一些样板代码。
我正在尝试创建一个可以被 ngFor 使用的 oberable。我试试:
statuses$ = Observable.create((o) => {
o.next(new NameValue('Open', 'OPEN'));
o.next(new NameValue('Closed', 'CLOSED'));
o.complete();
});
然后
<mat-option *ngFor="let status of statuses$ | async" [value]="status.value">
{{ status.name }}
</mat-option>
但我得到一个异步错误
找不到“Open”类型的不同支持对象“[object Object]”。 NgFor 只支持绑定到数组等Iterables
【问题讨论】:
-
subscribe返回Subscription对象,不可观察。 -
你为什么要订阅 和 使用异步管道?
-
错误地添加了订阅,但仍然失败。嗯。
标签: angular rxjs rxjs-observables