JavaScript logoJavaScript/
JS-0525

Use of controllers is discouragedJS-0525

Major severityMajor
Anti-pattern categoryAnti-pattern
angularjs

According to the Component-First pattern, we should avoid the use of AngularJS controller.

Rule based on Angular 1.x

Bad Practice

/*eslint angular/no-controller: 2*/

// invalid
angular.module('myModule').controller('HelloWorldController', function ($scope) {
    $scope.text = 'Hello World';
}); // error: Based on the Component-First Pattern, you should avoid the use of controllers
/*eslint angular/no-controller: 2*/

// valid
angular.module('myModule').directive('helloWorld', function () {
    return {
        template: '<div>{{ text }}',
        controller: function ($scope) {
            $scope.text = 'Hello World';
        }
    };
});