Skip to content

Latest commit

 

History

History
49 lines (32 loc) · 1.23 KB

prefer-component.md

File metadata and controls

49 lines (32 loc) · 1.23 KB

prefer-component -

Since AngularJS 1.5, we can use a new API when creating directives. This new API should be use when creating directive without DOM manipulation.

Rule based on Angular 1.5

Examples

The following patterns are considered problems;

/*eslint angular/prefer-component: 2*/

// invalid
angular.module('myModule').directive('helloWorld', function() {
    return {

    }
}); // error: Directive should be implemented with the component method.

The following patterns are not considered problems;

/*eslint angular/prefer-component: 2*/

// valid
angular.module('myModule').component('helloWorld', {
    template: '<h2>Hello World!</h2>'
});

// valid
angular.module('myModule').directive('helloWorld', function() {
    return {
        template: '<h2>Hello World!</h2>',
        link: function(){

        }
    };
});

Version

This rule was introduced in eslint-plugin-angular 0.16.0

Links