Because the type annotations are not supported in JavaScript, or as explained here:
What the heck is that
static get parameters()
? Angular2 is written in TypeScript, and normally depends on types to know what kind of objects to inject into class constructors as part of its dependency injection framework. Since these examples are in JavaScript and not TypeScript, we need a way to tell Angular what “types” of objects should be injected, without actually using types. The way we do this is with the static getterparameters
which attaches this type information to the class.
You can use TypeScript instead of JavaScript.
If you want to start a project with TypeScript support then make sure to specify the --ts
flag (as JavaScript is currently the default), for converting a JavaScript project to TypeScript follow the steps in the linked post: