Can you explain the use of "..." in Angular and what it is called? I am curious about why "...flash" is a parameter in the addFlash method within an array.push().
In the toggleFlash method, why is there "..." instead of using the this keyword?
flashs: IFlash[] = [];
flashs$ = new BehaviorSubject<IFlash[]>(this.flashs);
addFlash(flash: IFlash) {
this.flashs.push({
...flash,
show: false,
id: getRandomNumber()
});
}
toggleFlash(id: number) {
const index = this.flashs.findIndex(flash => flash.id === id);
this.flashs = [
...this.flashs.slice(0, index),
{
...this.flashs[index],
show: !this.flashs[index].show
},
...this.flashs.slice(index + 1)
];
this.flashs$.next(this.flashs);
}