How to re-trigger all pure pipes on all component tree in Angular 2

前端 未结 6 2225
青春惊慌失措
青春惊慌失措 2021-02-12 09:29

I have pure pipe TranslatePipe that translates phrases using LocaleService that has locale$: Observable current locale. I al

6条回答
  •  鱼传尺愫
    2021-02-12 10:12

    BEST PERFORMANCE SOLUTION:

    I figured out a solution for this. I hate to call it a solution, but it works.

    I was having the same issue with and orderBy pipe. I tried all the solutions here but the performance impact was terrible.

    I simply added an addtional argument to my pipe

    let i of someArray | groupBy:'someField':updated" 
    
    

    then anytime I perform an update to the array I simply to

    updateArray(){
        //this can be a service call or add, update or delete item in the array
          .then.....put this is in the callback:
    
        this.updated = new Date(); //this will update the pipe forcing it to re-render.
    }
    

    This forces my orderBy pipe to do a transform again. And the performance is a lot better.

提交回复
热议问题