Bạn cần sửa đổi hai tệp tslint.json và .angular-cli.json, giả sử bạn muốn thay đổi thành myprefix :
Trong tệp tslint.json chỉ cần sửa đổi 2 thuộc tính sau:
"directive-selector": [true, "attribute", "app", "camelCase"],
"component-selector": [true, "element", "app", "kebab-case"],
thay đổi "ứng dụng" thành "myprefix"
"directive-selector": [true, "attribute", "myprefix", "camelCase"],
"component-selector": [true, "element", "myprefix", "kebab-case"],
Trong tệp angular.json chỉ cần sửa đổi tiền tố thuộc tính:
(Đối với phiên bản góc nhỏ hơn 6, tên tệp là .angular-cli.json)
"app": [
...
"prefix": "app",
...
thay đổi "ứng dụng" thành "myprefix"
"app": [
...
"prefix": "myprefix",
...
Nếu trong trường hợp bạn cần nhiều hơn một tiền tố như @Salil Junior chỉ ra:
"component-selector": [true, "element", ["myprefix1", "myprefix2"], "kebab-case"],
Nếu tạo một dự án mới bằng Angular cli, hãy sử dụng tùy chọn dòng lệnh này
ng new project-name --prefix myprefix
ng generate component
ngay cả sau khi cập nhậttslint.json
:You are using different prefix from app, you might get lint errors. Please update "tslint.json" accordingly.
Tôi phải cập nhậtapps.prefix
tài sản.angular-cli.json
để thoát khỏi cảnh báo đó.