我的应用程序的结构如下:
<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/