Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Using the Angular CLI!
You have completed Using the Angular CLI!
Let's use the CLI to generate a new component.
Available Schematics
The following schematics are available for use with the ng generate
command:
- Class
- Component
- Directive
- Enum
- Guard
- Interface
- Module
- Pipe
- Service
Customizing the Component's Selector Prefix
There are two ways that you can customize the selector prefix when generating a component. You can use the ng generate
command's --prefix
option like this:
ng generate component [component-name-to-use] --prefix [selector-prefix-to-use]
Or you can configure the selector prefix to use via the .angular-cli.json
configuration file's apps[].prefix
property.
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "test-app"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "[selector-prefix-to-use]",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up