5

我对某些使用ng-bootstrapngb-pagination指令的组件进行了 Angular 测试。

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

// 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
}

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

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

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

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

PS:

4

2 回答 2

4

该规则directive-selector适用于@Directive装饰者。

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

例如:

// tslint:disable-next-line:component-selector
@Component({ template: ``, selector: 'ngb-pagination' })
于 2019-06-13T20:13:19.350 回答
2

您可以在您的angular.json文件内部scematics条目中设置它,如下所示:

您可以为组件和指令设置它

"schematics": {
    "@schematics/angular:component": {
      "prefix": ""
    },
    "@schematics/angular:directive": {
      "prefix": ""
    }
}

如果您使用命令行并且不经常生成组件/指令,则可以使用命令行执行此操作,如下所示:

ng generate component my-component --prefix ""

于 2019-06-13T20:35:10.413 回答