How to avoid a large number of dependencies in Angularjs

后端 未结 4 2020
旧时难觅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:03

    Try to move as much logic as possible to services, even just make controller methods act as "routing - passing through" methods . After time you will see it very usefull if you will want to use similar methods in other controllers/directives. Anyway, 7 injections is in my opinion not much :)

    (edit: see the comment of Matt Way below) Also, a tip - in newer versions of Angular you don't have to write this array, just:

    app.controller('viewapps', function($scope,Appfactory,Menu, $timeout,filterFilter,Notice,$routeParams){
       //controller code..    
    }])
    

提交回复
热议问题