Is there a way to create a new reference to an array without directly manipulating the array itself? I'm facing an issue with an Angular pipe that doesn't detect changes made through push/pop operations. I want to avoid solutions like this:
this.array = this.array.filter(e=>true)
Adding unnecessary complexity just to update the reference. I attempted another method, but it didn't work as expected (the pipe failed to detect any changes) and my lack of familiarity with JavaScript/Typescript prevents me from understanding why.
const newRef = this.array;
this.array = null;
this.array = newRef
I have a pipe that takes in an array of objects and an array of filters, and returns a filtered array of objects.
@Pipe({
name: 'eventFilter'
})
export class EventFilterPipe implements PipeTransform {
transform(events: EventDtos[], filters:Filter[]): any {
//return filtered events
}
Pipe usage:
<div class="event" *ngFor="let event of events | eventFilter:filters">
html stuff
</div>
When adding or removing a filter from filters
, the pipe's transform is not triggered, so I use the following code to force the transform
call:
this.filters = this.filters.filter(e=>true)
However, I am unsure whether this method is faster than using an impure pipe. Ideally, I would like to stick with the pure pipe and update the filters
reference without complicating things further.