如何禁用 Angular 样式指南的 tslint 规则:“选择器应以 <prefix>"为前缀? [英] How to disable tslint rule for Angular style guide: &quot;The selector should be prefixed by &lt;prefix&gt;&quot;?

查看:36
本文介绍了如何禁用 Angular 样式指南的 tslint 规则:“选择器应以 <prefix>"为前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对一些使用来自 ngb-pagination 的组件进行了 Angular 测试noreferrer">ng-bootstrap.

现在,在我的测试中,我模拟这个组件如下:

//在下一行我得到:选择器应该以

"为前缀(https://angular.io/guide/styleguide#style-02-07)(组件选择器)@Component({ 模板: ``, 选择器: 'ngb-pagination' })类 DummyNgPagination {//这里有一些数据,与问题无关}

在放置 @Component 注释的行中,我收到一个 tslint 错误,指向 样式 02-07.

我尝试通过执行以下操作来禁用该规则,但结果是一样的.

//tslint:disable-next-line:directive-selector@Component({ 模板: ``, 选择器: 'ngb-pagination' })

如何为该特定行禁用该规则?

附注:

解决方案

directive-selector 规则适用于 @Directive 装饰器.

对于 @Component 你需要使用 component-selector

例如:

//tslint:disable-next-line:component-selector@Component({ 模板: ``, 选择器: 'ngb-pagination' })

I have an Angular test for some component which uses the directive ngb-pagination from ng-bootstrap.

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.

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:

解决方案

The rule directive-selector works for the @Directive decorator.

For a @Component you need to use component-selector

For example:

// tslint:disable-next-line:component-selector
@Component({ template: ``, selector: 'ngb-pagination' })

这篇关于如何禁用 Angular 样式指南的 tslint 规则:“选择器应以 <prefix>"为前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆