angular - 组件 "AppFooterComponent"的选择器应该用作元素

标签 angular tslint

我的应用程序的结构如下:

<body>
  <header>[...]</header>
  <main>[...]</main>
  <footer><app-footer></app-footer></footer>
</body>

因为我不想要不必要的 DOM 元素,所以我更喜欢声明 app-footer作为一个属性,所以我可以像这样声明页面:
<body>
  <header>[...]</header>
  <main>[...]</main>
  <footer app-footer></footer>
</body>

但是如果我这样做,我在执行 ng lint 时会收到以下错误消息

The selector of the component "AppFooterComponent" should be used as element (https://angular.io/styleguide#style-05-03)



我认为这个案例是规则的合法异常(exception)。你同意?如果是这样,我如何将此特定组件声明为此规则的异常(exception)?

最佳答案

尽管这被认为是一种不好的做法(根据样式指南),但您仍然可以为此特定组件禁用此特定 ts lint 规则。

为此,请在组件注释之前使用/* tslint:disable:component-selector */,以便组件声明如下所示:

/* tslint:disable:component-selector */
@Component({
    selector: '[app-footer]',
    templateUrl: './app-footer.component.html'
})
export class AppFooterComponent 

关于angular - 组件 "AppFooterComponent"的选择器应该用作元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51157665/

相关文章:

html - Angular 可滚动的 div

javascript - Ionic 在一个按钮内创建两个按钮

import - 如何使用 tslint 的导入排序规则对导入进行排序

为表单设置 ngModel 时,默认情况下未选中 Angular 5 单选按钮

angular - 在组件标签之间呈现内容

使用延迟加载模块和 systemjs 的 Angular2 AOT 编译

javascript - Typescript文件编译完成后为什么要执行ESlint?

tslint - 禁止使用 TSLint 设置数组属性

typescript - VS code 中的 Tslint.config 格式化/美化

typescript - 允许没有未使用的变量规则的 typescript 编译