In my first blog, Setting up your first project in angular 7 using Angular-CLI, we discussed how to create an Angular project using Angular CLI. Now, let's discuss how to change the prefix of an Angular component.
Suppose, you create an Angular application. After some time, you realize that you need to change your prefix name as per the client requirement. Don't worry! You don't have to create a new application for this. Angular provides a solution to change the prefix name.
Let's take an example. You created a component called 'home' component using Angular CLI command. By default, the home component selector is like <app-home> and you want to change this to your prefix name like <myprefix-home>.
To implement the above scenario, we have two options.
- Change prefix for components in an old project
- Change prefix for components in a new project using the command line.
Change prefix for components in an old project
Suppose, you have an old project and you want to change the prefix for the component, then you need to follow the below two steps,
STEP 1 - Change component-selector in tslint.json
Go to the tslint.json file. The path for tslint.json is D:\your-foldername\your project name\src\tslint.json,
- {
- "extends": "../tslint.json",
- "rules": {
- "directive-selector": [
- true, "attribute", "app", "camelCase"
- ],
- "component-selector": [
- true, "element", "app", "kebab-case"
- ]
- }
- }
As you can see 'app' under the 'component-selector' in above code snipped, go and change the app and write your prefix name for your component.



SatishPosted Jul 24, 2020, 12:24 AM
Or set a dynamic component prefix so that whenever want to change it will replace all the component's prefix.
SatishPosted Jul 24, 2020, 12:23 AM
How to change the previous component prefix in one go.
Mahesh VermaPosted Apr 5, 2019, 9:24 AM
Well done....very informative blog.
Cris GomezPosted Apr 4, 2019, 11:25 AM
Well done, nice tutorial... thx