[英]How to disable tslint rule for Angular style guide: "The selector should be prefixed by <prefix>"?
I have an Angular test for some component which uses the directive ngb-pagination
from ng-bootstrap .我对使用来自ng-bootstrap的指令
ngb-pagination
的某些组件进行了 Angular 测试。
Now, in my test I mock this component as follow:现在,在我的测试中,我模拟了这个组件,如下所示:
// on next line I get: The selector should be prefixed by "<prefix>" (https://angular.io/guide/styleguide#style-02-07) (component-selector)
@Component({ template: ``, selector: 'ngb-pagination' })
class DummyNgPagination {
// some data here, not relevant in to the question
}
In the line where it is placed the @Component
annotation I get a tslint error pointing to Style 02-07 .在放置
@Component
注释的行中,我得到一个指向Style 02-07的tslint错误。
I tried to disable the rule by doing the following, but the result is the same.我尝试通过执行以下操作来禁用规则,但结果是一样的。
// tslint:disable-next-line:directive-selector
@Component({ template: ``, selector: 'ngb-pagination' })
How can I disable that rule for that specific line?如何为该特定行禁用该规则?
PS: PS:
The rule directive-selector
works for the @Directive
decorator.规则
directive-selector
适用于@Directive
装饰器。
For a @Component
you need to use component-selector
对于
@Component
,您需要使用component-selector
For example:例如:
// tslint:disable-next-line:component-selector
@Component({ template: ``, selector: 'ngb-pagination' })
You can set that inside your angular.json
file inside scematics
entry like so:您可以在
scematics
条目中的angular.json
文件中设置它,如下所示:
You can set it for both Components and directives您可以为组件和指令设置它
"schematics": {
"@schematics/angular:component": {
"prefix": ""
},
"@schematics/angular:directive": {
"prefix": ""
}
}
And if you are using the command line and you don't generate components/directives frequently, you can do that using the command line like so:如果您使用命令行并且不经常生成组件/指令,则可以使用命令行执行此操作,如下所示:
ng generate component my-component --prefix ""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.