What is "..." in Angular2? What its purpose?

Ronald Abellano

What is ... in Angular? And what it is called? I'm thinking what is the use of "...flash" in addFlash method where it is a parameter in the array.push()?

And also in the toggleFlash method why there is "..." if we can just use 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);
}
jitender

... is es6 Spread_syntax in your code ...this.flashs will add this.flashs items to the array where you'r use it while {...this.flashs[index] will add the properties of the object at given index to the object where you'r using it read the comments in code below for further explanation

 this.flashs = [
        ...this.flashs.slice(0, index),//slice flashs array and add result items here like obj1,obj2....
        {
            ...this.flashs[index],//get object at given index and add that object properties here like prop1:val,prop2:val,...
            show: !this.flashs[index].show
        },
        ...this.flashs.slice(index + 1)
    ];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What is UI Bootstrap and what is its purpose?

What is yum - q and what's its purpose?

What is the purpose of 'Output properties' in Angular2 directives?

What is the purpose of setTimeout in Angular?

What is the purpose of Angular animations?

__ctype_b_loc what is its purpose?

Kotlin - coroutine yield() what is its purpose?

What is the purpose of including the type in its definition in haskell?

Webpack postcss loader, what's its purpose?

Inner Class. What is its purpose?

.NET MySqlCommand.Transaction - what is its purpose?

What is React Native's bundle, and its purpose?

What is the purpose of .*\\?

What is the purpose of "?"

What is the purpose of angular-sanitize ?

What is the purpose of Angular rendering engine?

What are the arguments of syscall (2) and their purpose?

What is the purpose of the esm directories in the Angular 2 modules?

What is the purpose of ApplicationRef in Angular 2+?

Docker, what is it and what is the purpose

Android - gradle testProguardFile - what is its purpose relating to unit tests

Android Firebase Test Lab - instrumentation tests with Orchestrator, what is its purpose?

X-Original-For header: what's its purpose?

Does Dovecot-LDA need the -f argument (and what is its purpose)?

what is bundle installation script and its sole purpose in Netsuite?

What is the purpose of square bracket usage in Angular?

What is the purpose of SwUpdate.activateUpdate() in Angular?

Dagger 2 - what is the purpose of a @Singleton annotation class

What is the purpose of "pm2 save"?