Manually trigger pipe update
Create a pipe, here are two way to solve it:
1, but this way will be trigger for many times, which is bad for your website.
@Pipe({
name: 'tablepipe',
pure: false
})
2.Using ngModel + pure pipe
<input
style="position: absolute;
z-index: -1;"
[(ngModel)]="detectedChangeRef">
this.detectedChangeRef = Math.random();
your html, because pipe would notice your ref's change, it would trigger your pipe:
*ngFor="let item1 of item | tablepipe:detectedChangeRef;">
Your pipe
transform(value,detectedChangeRef) {
console.log(detectedChangeRef);
// do sth..
}
First way: paremeter
One way to make a Pure Pipe becoming impure is add a parameter
to your Pipe
.
when you want to refresh, just change the parameter.
Second way: without parameter
Pure Pipe will be fired when its input has a new instance. So with TypeScript 2.1+, the below code will copy the original object with a new instance, and lead pure pipe to be fired.
let copy = { ...original }
Negative impact
This will force your component to refresh your pipe every time a variable changes his value, even if this isn't the one used within the pipe contains
Stackblitz
Both ways are included in stackbliz demo.