看来,当我使用Angular cli创建一个Angular 2应用程序时.我的默认组件前缀是AppComponent的app-root.现在,当我将选择器更改为其他名称为"abc-root"时
@Component({
selector: 'abc-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
Run Code Online (Sandbox Code Playgroud)
vscode警告我,
[tslint] The selector of the component "AppComponent" should have prefix "app"
Run Code Online (Sandbox Code Playgroud)
Neh*_*nia 254
您需要修改两个文件tslint.json和.angular-cli.json,假设您要更改为myprefix:
在tslint.json文件中,只需修改以下2个属性:
"directive-selector": [true, "attribute", "app", "camelCase"],
"component-selector": [true, "element", "app", "kebab-case"],
Run Code Online (Sandbox Code Playgroud)
将"app"更改为"myprefix"
"directive-selector": [true, "attribute", "myprefix", "camelCase"],
"component-selector": [true, "element", "myprefix", "kebab-case"],
Run Code Online (Sandbox Code Playgroud)
在angular.json文件中只需修改属性前缀:( 对于小于6的角度版本,文件名为.angular-cli.json)
"app": [
...
"prefix": "app",
...
Run Code Online (Sandbox Code Playgroud)
将"app"更改为"myprefix"
"app": [
...
"prefix": "myprefix",
...
Run Code Online (Sandbox Code Playgroud)
如果在这种情况下你需要多个前缀@Salil Junior指出:
"component-selector": [true, "element", ["myprefix1", "myprefix2"], "kebab-case"],
Run Code Online (Sandbox Code Playgroud)
如果使用Angular cli创建新项目,请使用此命令行选项
ng new project-name --prefix myprefix
Run Code Online (Sandbox Code Playgroud)
小智 18
angular-cli.json:"prefix":"defaultPrefix",以便angular-cli将使用它来生成组件.tslint.json像这样的Ajust :
"directive-selector": [
true,
"attribute",
["prefix1", "prefix2", "prefix3"],
"camelCase"
],
"component-selector": [
true,
"element",
["prefix1", "prefix2", "prefix3"],
"kebab-case"
],
Run Code Online (Sandbox Code Playgroud)And*_*lva 16
实际上,使用Angular Cli,您只需更改angular-cli.json位于根应用程序上的"apps"数组内的"prefix"标记.
改变"TheBestPrefix",就像这样.
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "TheBestPrefix",
"mobile": false,
"styles": [
"styles.css"
],
"scripts": [],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
]
Run Code Online (Sandbox Code Playgroud)
使用CLI生成新组件时,ng g component mycomponent
组件标记将具有以下名称"TheBestPrefix-mycomponent"
Ani*_*Das 11
对于angular 6/7以后会有一个tslint.json你里面/src的文件夹,其保存tslist为组件和指令的规则。
{
"extends": "../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"directivePrefix",
"camelCase"
],
"component-selector": [
true,
"element",
"compoenent-prefix",
"kebab-case"
]
}
}
Run Code Online (Sandbox Code Playgroud)
更改该文件将解决此问题。
| 归档时间: |
|
| 查看次数: |
57779 次 |
| 最近记录: |