Angularjs Clean Code Advices


Hello everybody,

today I want to share with you fragment of knowledge from John Papa and his course at pluralsight entitled AngularJS Patterns: Clean Code.

Inside of course one of the videos he have following structure advice: Function, Inject, Register ( I will name it FIR  ).

function DashBoardController(service1, service2) {//function

    //here goes code of controller.


DashBoardController.$inject = ['service1', 'service2'];//inject



    .controller('DashBoardController', DashBoardController);//register

or in the form of image:

And as John Papa mentioned, Todd Motto also likes that approach:

"I prefer this sequence: write my function, inject the dependencies, ship it off into the app. It makes sense from hoisting and declarative prospectives".


But in one of projects where I used to work, company had another approach: Register, Inject, Function. You maybe can ask: "Why?". The answer is pretty simple: if your function is pretty big, then it can be not convenient to scroll it

No Comments


Add a Comment


Comments are closed