Injectables not working in angular 2.0 Injectables not working in angular 2.0 angular angular

Injectables not working in angular 2.0


Your compiler does not add parameters properties to the MyAppComponent (from looking at your pluker). I think this is the problem. If you add

MyAppComponent.parameters = [[Names]]

then all will works well.

  1. Here is your plunker with fix.
  2. Here is the same example in TS (with ES6)

UPD Thanks to @GrayFox for pointing out the correct way (see the comment bellow):

For future references - use --emitDecoratorMetadata flag when using tsc or add emitDecoratorMetadata: true to the configuration if you're using gulp-typescript

See TypeScript compiler options here (you can find emitDecoratorMetada there).


Put this:

 <PropertyGroup Condition=" '$(Configuration)' == 'Debug' " >   <DebugSymbols>true < /DebugSymbols>   < TypeScriptRemoveComments > false < /TypeScriptRemoveComments>   < TypeScriptSourceMap > true < /TypeScriptSourceMap>   < TypeScriptAdditionalFlags > $(TypeScriptAdditionalFlags)--emitDecoratorMetadata < /TypeScriptAdditionalFlags> < /PropertyGroup> < PropertyGroup Condition= " '$(Configuration)' == 'Release' " >   <DebugSymbols>true < /DebugSymbols>   < TypeScriptRemoveComments > true < /TypeScriptRemoveComments>   < TypeScriptSourceMap > false < /TypeScriptSourceMap>   < TypeScriptAdditionalFlags > $(TypeScriptAdditionalFlags)--emitDecoratorMetadata < /TypeScriptAdditionalFlags> < /PropertyGroup>

into your *.njsproj file at the end.