Hat jemand, warum dieser Code (Initialisierung eines Wertes von Subject) nicht funktioniert? Gibt es einen Fehler oder ein Design? Was mache ich falsch?Subject.next feuert nicht in ngOnInit
ts
import { Component, OnInit } from '@angular/core';
import { Subject } from "rxjs";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.styl']
})
export class AppComponent implements OnInit {
itemSupplier$: Subject<any[]> = new Subject<any[]>();
items: any[] = [
{name: 'Item 1', value: 'item1'},
{name: 'Item 2', value: 'item2'},
];
ngOnInit(){
this.itemSupplier$.next(this.items);
}
}
html
<ul>
<li *ngFor="let item of itemSupplier$ | async">{{item.name}}</li>
</ul>
Könnten Sie auf * "funktioniert nicht" * erweitern? – jonrsharpe