How do the function argument names in Angular.js objects connect to other objects?

前端 未结 2 709
醉梦人生
醉梦人生 2021-02-04 03:19

Let\'s say I have made a module with a service and a controller in Angular.js, I am able to access that service inside of the controller like so:

var myapp = ang         


        
2条回答
  •  太阳男子
    2021-02-04 04:15

    This is accomplished by the quite clever method annotate (source) which takes a regex scan on function signature source (using function.toString()) and iteratively pushes each function argument into the function $inject array.

    The same result is accomplished when manually specifying the $inject array as in:

    var MyController = function($scope, myService) {
      // ...
    }
    // Define function dependencies
    MyController.$inject = ['$scope', 'myCustomService'];
    

提交回复
热议问题