How to $inject into Angular class w/ES6
That is an experimental proposed syntax. In Babel, you'd have to enable es7.classProperties
. Pass
optional: ['es7.classProperties']
to babel. The exact method depends on how you are transpiling.
If you wanted to do standard ES6, you could also do
static get $inject(){ return ["$scope", "$state", "$window"]; }
Another approach would be use $injector.annotate(fn)
, which Angular uses for dependency injection, and which allows you to get arguments of the function you pass to it. You could utilize it to get the names of all constructor()
parameters, and retrieve them using $injector.get()
.
Here's a link to answer in another thread, and a direct link to a fiddle with a demo.