1. 程式人生 > >Angular5 tslint錯誤:The selector of the component “XXXComponent” should be used as element

Angular5 tslint錯誤:The selector of the component “XXXComponent” should be used as element

錯誤描述

在專案中自己封裝了一個 select 元件

@Component({
    selector: '[app-choosen-select]',
    templateUrl: './selectcommon.component.html',
    styleUrls: ['./style.scss']
})
export class SelectCommonComponent implements OnInit, AfterViewInit, OnDestroy {

ts編譯報錯。

解決方案

修改tslint.json

"component-selector": [
      true,
      "element",
      "app",
      "kebab-case"
    ],

改為

"component-selector": [
      true,
      ["element","attribute"],
      "app",
      "kebab-case"
    ],

元件引用


<div app-choosen-select [options]="groupOptions" class="cpu-select-round"></div>