Cristiano Fontes Cristiano Fontes - 6 months ago 56
Javascript Question

Why the need for () when importing services in Angular 2?

I am studying angular 2 and have found this statement disturbing.

Don't forget the parentheses! Neglecting them leads to an error that's
difficult to diagnose.

While reading this

Why is there a parenteses there what is it's function? Why have it there in the first place if it causes "hard to throubleshoot" problems?



These parens are not related to imports but to decorators

@Injectable() // correct
export class MyService {...}


@Injectable // wrong
export class MyService {...}

because a function reference is quite different from a function invocation.