Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用动态ngrx选择器或ngrx操作以获得更好的性能?_Angular_Redux_Store_Ngrx - Fatal编程技术网

Angular 使用动态ngrx选择器或ngrx操作以获得更好的性能?

Angular 使用动态ngrx选择器或ngrx操作以获得更好的性能?,angular,redux,store,ngrx,Angular,Redux,Store,Ngrx,我将根据参数从存储中获取数据 export const selectSchedulingsTimes = createSelector( schedulings, (state: ISchedulesState, { time }: { time: string }) => { let nowFormat = moment(time, 'HH:mm'); return state.schedulings.data.filter(elm => { l

我将根据参数从存储中获取数据

export const selectSchedulingsTimes = createSelector(
  schedulings,
  (state: ISchedulesState, { time }: { time: string }) => {
    let nowFormat = moment(time, 'HH:mm');
    return state.schedulings.data.filter(elm => {
      let before = moment(elm.tp_org_r, 'HH:mm:ss');
      let after = moment(elm.tp_des_r, 'HH:mm:ss');

      let checkifBetween = nowFormat.isBetween(before, after);

      if (checkifBetween) {
        return elm;
      }
    });
  }
);
我已经创建了选择器,但是使用了静态参数

export const selectSchedulingsTimes = createSelector(
  schedulings,
  (state: ISchedulesState, { time }: { time: string }) => {
    let nowFormat = moment(time, 'HH:mm');
    return state.schedulings.data.filter(elm => {
      let before = moment(elm.tp_org_r, 'HH:mm:ss');
      let after = moment(elm.tp_des_r, 'HH:mm:ss');

      let checkifBetween = nowFormat.isBetween(before, after);

      if (checkifBetween) {
        return elm;
      }
    });
  }
);
然后在我的组件中传递参数

export class LineSynopticComponent implements OnInit, AfterViewInit {

  schedules$ = this.store.pipe(select(selectSchedulingsTimes, { time: '10:34' }));

ngOninit(){
}
因为
schedules$
没有在它里面声明,如果我设置一个变量而不是
10:34
它会工作吗


使用减速机是否更好?返回值或选择器的性能更高?

使用参数调用选择器没有问题。只要在调用选择器时确保参数存在。我会这样做:

  • 声明你的可观察性
  • 在参数可用的地方调用选择器,我使用了onInit,因为这是您提供的唯一内容

    schedules$: Observable<any> // whatever type it should be returning
    
    ngOninit(){
       this.schedules$ = this.store.pipe(select(selectSchedulingsTimes, { time: '10:34' }));
    }
    
    schedules$:Observable//它应该返回的任何类型
    恩戈尼尼特(){
    this.schedules$=this.store.pipe(select(selectSchedulingTimes,{time:'10:34'}));
    }
    

你的回答回答了我的问题,但我现在有另一个问题。这是问题链接