I don't understand the use of $inject in controllers

后端 未结 4 1654
执笔经年
执笔经年 2020-11-28 23:50

I am totally confused about inject in Angular. I do not know where to use it and why. Is it only used with factory as described here?

myController.$inject =          


        
4条回答
  •  执笔经年
    2020-11-29 00:01

    To complement @mark answer, it is important to note that using the $inject method in the style of:

    MyController.$inject = ['$scope', 'notify'];
    

    allows you to add injection dependencies when building providers which are the only angular recipes that don't allow 'friendly' annotation style i.e.:

    .controller('MyController', ['$scope', 'notify',... 
    

    dependencies to be declared.

提交回复
热议问题