我从此标记中收到错误Argument of type '() => Observable<Device[]>' is not assignable to parameter of type 'Promise<any>'
:
<div *ngIf="(deviceStoreService.getDevices | async) as devices">
<tr *ngFor="let device of devices">
<td>{{device.name}} <midi-keyboard [device]="device"></midi-keyboard></td>
</tr>
</div>
我从这个标记中得到了相同的错误:
<tr *ngFor="let device of (deviceStoreService.getDevices | async)">
<td>{{device.name}} <midi-keyboard [device]="device"></midi-keyboard></td>
</tr>
如果我分配带有标记的控制器类成员变量,我不会收到错误消息:
<tr *ngFor="let device of (devices | async)">
<td>{{device.name}} <midi-keyboard [device]="device"></midi-keyboard></td>
</tr>
和控制器类:
export class DeviceComponent implements OnInit {
devices: Observable<Array<Device>>;
constructor(
private deviceStoreService: DeviceStoreService,
) { }
ngOnInit() {
this.devices = this.deviceStoreService.getDevices();
}
这是为什么?
答案 0 :(得分:0)
您缺少父母。如果getDevices
是一个函数,则
<div *ngIf="(deviceStoreService.getDevices() | async) as devices">