[英]RxJS Observables: Creating with values
I don't yet have the service to call for the values, so I am doing some boiler plate code with aysnc ngFors.我还没有调用这些值的服务,所以我正在用 aysnc ngFors 做一些样板代码。
I am trying to create an obserable that can be consumed by an ngFor.我正在尝试创建一个可以被 ngFor 使用的可观察对象。 I try:我尝试:
statuses$ = Observable.create((o) => {
o.next(new NameValue('Open', 'OPEN'));
o.next(new NameValue('Closed', 'CLOSED'));
o.complete();
});
then然后
<mat-option *ngFor="let status of statuses$ | async" [value]="status.value">
{{ status.name }}
</mat-option>
but I get an Async error但我收到一个异步错误
Cannot find a differ supporting object '[object Object]' of type 'Open'.找不到类型为“Open”的不同支持对象“[object Object]”。 NgFor only supports binding to Iterables such as Arrays NgFor 只支持绑定到 Iterables,比如 Arrays
Simulate your observable like this:像这样模拟你的 observable:
import { of } from 'rxjs';
statuses$ = of([new NameValue('Open', 'OPEN'), new NameValue('Closed', 'CLOSED')]);
which gives an array that *ngFor
can interpret, rather than the object you are returning currently.它给出了一个*ngFor
可以解释的数组,而不是您当前正在返回的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.