如何在 angular ngrx 的效果中传递 id

How to pass id in effects in angular ngrx

我正在选择一个列表,基于此我需要显示所选列表的信息。

我对ngrx确实不熟悉,只是尝试订阅observable并获取最后一个对象:

View()方法:

constructor(private store: Store<IUserState>) {}

public user$: Observable<IUser[]>; -- declare once 

view(id) {
  this.store.dispatch(fromUserActions.loadUser({ id: id }));
  this.store.select(userQuery.getEntity).subscribe(value => {
    this.user$ = value[value.length - 1]; -- and assing the data as per values
    console.log(value[value.length - 1]);
  });
}

HTML:

<pre *ngIf="userLoaded$">
    {{user$ | json}}
</pre>  -- Removed async pipe

编辑:

view(id) {
    this.store.dispatch(fromUserActions.loadUser({ id: id }));
    this.store.select(userQuery.getEntity).subscribe(value => {
      this.user$ = new Observable<IUser>();
      this.user$ = value.filter(x=> x.id == id)[0];
      console.log(value.filter(x=> x.id == id)[0]);
    });
}

Demo