How to $inject into Angular class w/ES6

后端 未结 2 1855
误落风尘
误落风尘 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 05:17

    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"]; }
    

提交回复
热议问题