Cristiano Fontes Cristiano Fontes - 1 year ago 88
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?


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download