您需要修改两个文件tslint.json和.angular-cli.json,假设您想更改为myprefix:
在tslint.json文件中,只需修改以下2个属性:
"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"],
在angular.json文件中,只需修改属性前缀:(
对于小于6的Angular版本,文件名为.angular-cli.json)
"app": [
...
"prefix": "app",
...
将“ app”更改为“ myprefix”
"app": [
...
"prefix": "myprefix",
...
如果您需要多个前缀,如@Salil Junior指出:
"component-selector": [true, "element", ["myprefix1", "myprefix2"], "kebab-case"],
如果使用Angular cli创建新项目,请使用此命令行选项
ng new project-name --prefix myprefix
ng generate component
即使在更新后,我也收到警告tslint.json
:You are using different prefix from app, you might get lint errors. Please update "tslint.json" accordingly.
我必须更新apps.prefix
属性.angular-cli.json
以摆脱该警告。