How to avoid a large number of dependencies in Angularjs

后端 未结 4 2021
旧时难觅i
旧时难觅i 2021-02-05 08:46

I have an Angular application. Its working good, but as my application is getting bigger I\'m worried about the large number of dependencies that I have to inject in each contro

4条回答
  •  清歌不尽
    2021-02-05 09:21

    My approach is to use $injector, when there are lots of dependencies:

    app.controller('viewapps', ['$scope','$injector',function($scope,$injector){                               
        var Appfactory = $injector.get('Appfactory');
        var Menu = $injector.get('Menu'); 
        //etc...
    }]);
    

    The advantages:

    • Code can be minified and obfuscated safely
    • You don't need to count the index of the dependency, when you declare dependency as a function's parameter

提交回复
热议问题