Number of lines and number of parameters in a function for angular controllers

I am using SonarQube for my angularJS application.

I'm having problems because Sonar discovers that my controller, which is a function, has too many lines (over 100), as well as a number of parameters (over 7).

Since controllers are functions in angular JS, it seems normal to me that these numbers can easily be exceeded.

+4
source share
1 answer

If you use syntax controller as, you can add your controller functions to it instead of one massive function. eg.

var MyController = function($http) {
    this.$http = $http;
}

MyController.$inject = ['$http'];
angular.module('myApp').controller('MyController', MyController);

MyController.prototype.someFunc = function() {
    return this.$http.get('something');
}
+1
source

All Articles