Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elipsis in front of Angular2 Classes (Collections in this case)

Tags:

syntax

angular

Why are there in many examples elipsis, or three dots in front of an Angular2 Import.

It doesn't seem to be required, I can remove them and my application will still work. I saw this "pattern" in angular2 examples and in the seed I'm using.

I however would like to understand why this is done, I'm not sure if I'm looking for the wrong phrases because I've tried to look this up multiple times before.

providers: [...FORM_PROVIDERS],
directives: [ ...ROUTER_DIRECTIVES]

seems to be the same as

providers: [FORM_PROVIDERS],
directives: [ROUTER_DIRECTIVES]

Is it just for clarifying these are multiple providers/components?

like image 796
Mathijs Segers Avatar asked Mar 04 '16 10:03

Mathijs Segers


1 Answers

From my comments above.

What you call ellipsis is the ES2015 spread operator.

Otherwise, FORM_PROVIDERS , ROUTER_DIRECTIVES and others are basically arrays of providers, they're just spread in a new array instance. This allows you to pass a flat array of providers if you add multiple of those.

like image 198
Ludohen Avatar answered Sep 25 '22 09:09

Ludohen