Angular launch of 2 pipes

I have a collection of models. In the template, I use pipe

<div class="card-panel" *ngFor="let card of cards | sortByType"> <card-view [card]="card" [autoupdate]="true"></card-view> </div> 

In each component, I have a timer for the update data. But when the model is updated, the pipe did not start again. Is there a way to force the pipe to run or make a few angular in this situation.

In the card view, I have a timer that updates the map variable. But angular doesn't catch these changes to trigger the channel

+6
source share
1 answer
  • You can create a copy of cards than Angular2, change detection detects a change and starts the channel again.

  • You can make unclean piping

 @Pipe({ name: 'sortByType', pure: false}) 

this causes your pipe to run every time change detection is performed.

You can perform a custom change using IterableDiffer and return the caching result when the array has not actually changed.

With this option, you must be careful not to cause serious performance degradation.

  • You can pass an additional parameter to the updated channel (for example, a number that increases each time the array changes.

Thus, the channel is invoked because Angular change detection invokes the channel every time a value or parameter changes.

The disadvantage is that it is a little more cumbersome to use.

+13
source

Source: https://habr.com/ru/post/1011798/


All Articles