看起来,当我使用Angular cli创建Angular 2应用程序时.我的默认组件前缀是AppComponent的app root.现在,当我将 Select 器更改为其他选项时,请说"abc根"

@Component({
  selector: 'abc-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

vscode警告我,

[tslint] The selector of the component "AppComponent" should have prefix "app"

推荐答案

您需要修改两个文件tslint.json和.好的.json,假设您想要更改为myprefix:

In the tslint.json file just modify the following 2 attributes:

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

将"app"更改为"myprefix"

"directive-selector": [true, "attribute", "myprefix", "camelCase"],
"component-selector": [true, "element", "myprefix", "kebab-case"],

In the angular.json file just modify the attribute prefix:

"app": [
  ...
  "prefix": "app",
  ...

将"app"更改为"myprefix"

"app": [
  ...
  "prefix": "myprefix",
  ...

If in the case you need more than one prefix as 100 point out:

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

If creating a new project using Angular cli use this command line option

ng new project-name --prefix myprefix

Angular相关问答推荐

单元测试 case 模拟store 中的行为主体

RXJS运算符用于combineLatest,不含空值

Angular 17自定义指令渲染不起作用'

如何用Effect()识别正确的Angular 信号?

角material 17 -如何从Style.scss中的主题中获取原色

如何在滑动滑块中获取当前项目的索引?

无效的ICU消息.缺少';}';|Angular material 拖放(&A)

当元素在元素上使用迭代变量时,如何重构ngFor?

ngx-http-client 在 Angular 16 中已弃用

使用 TAB 键时如何聚焦mat-select组件?

在 Angular 2 中订阅路由参数和查询参数

如何从Angular 2 中的按钮单击触发输入文件的单击事件?

material Angular手风琴header/title高度

在同一个组件中使用 MatSort 的多个 mat-table

如何在 Angular CLI 1.1.1 版中将路由模块添加到现有模块?

如何在 Angular2 中的所有请求的请求标头中发送Cookie?

实现自定义 NgbDateParserFormatter 来更改 NgbInputDatepicker 上输入值的格式是否正确?

如何在悬停时向元素添加类?

Angular 2:将外部js文件导入组件

如何在 Angular 2 中动态添加和删除表单字段