如何修复 angular 8 中的 jw-modal 选择器问题

How to fix jw-modal selector issue in angular 8

我有下面的代码,当我在 node.js 中 运行 命令 "npm run lint" 我在选择器第 4 行出现错误(选择器应该以 [=21= 为前缀]).我尝试这样做:"app-jw-modal",所有模态内容都出现在主页上。

是否有解决前缀问题的方法,如选择器问题?

comp.ts

1. import { Component, ViewEncapsulation, ElementRef, Input, OnInit, OnDestroy } from '@angular/core';
2. import { ModalService } from './modal.service';

3. @Component({ 
4.  selector: 'jw-modal', 
    templateUrl: 'modal.component.html', 
    styleUrls: ['modal.component.less'],
    encapsulation: ViewEncapsulation.None
})

有两种方法可以解决此问题。

1.

jw-modal 的所有实例更改为 app-jw-modal。这将包括当前正在使用选择器的任何地方。

如果像这样在任何组件中引用它:

<jw-modal></jw-modal>

变成:

<app-jw-modal></app-jw-modal>

2.

修改 TSLint 规则以满足您的需要。

{
  "extends": "../../tslint.json",
  "rules": {
    "component-selector": [true, "element", "app", "kebab-case"]
  }
}

您可以修改此规则,选择需要的前缀,也可以关闭此规则。