How to $inject into Angular class w/ES6

后端 未结 2 1885
误落风尘
误落风尘 2021-01-02 04:46

Using Angular 1.4 with ES6/7 and Babel, I can successfully inject parameters into a class named Controller with this code after the class block:

class Co         


        
2条回答
  •  忘掉有多难
    2021-01-02 04:59

    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.

提交回复
热议问题