Angular视图未更新新的可观察数据



我有一个角分量使用这样的构造函数:

    newTrips$: Observable<Trip[]>;
    constructor(private store: Store<fromRoot.State>, private tripFeedService: TripFeedService) {
       this.newTrips$ = store.select(fromRoot.getTripFeedUnreadTrips);
       this.newTrips$.subscribe(x => { console.log('subscribe'); console.log(x); });
    }

在视图中,我有一个:

<div *ngFor="let trip of newTrips$ | async">test</div>

问题是,如果加载页面,则行程[]为空。NGFOR在视图中永远不会被称为。我的控制台确实显示了显示"订阅"和列表中的对象的日志消息。如果刷新页面,则显示项目,并且可观察到的所有以下更改都正确显示在控制台和UI

由于您在ngFor中使用async,因此无需订阅构造函数内的可观察到的。

newTrips$: Observable<Trip[]>;
    constructor(private store: Store<fromRoot.State>, private tripFeedService: TripFeedService) {
       this.newTrips$ = store.select(fromRoot.getTripFeedUnreadTrips);
    }

最新更新