How to Create Component in Angular 10
Today, we will explain to you how to create a component in angular 10. in this article will know you how to create components using the ng generate component command.
You can easily create the new components using the Angular CLI command. so you can follow steps for creating components using Angular CLI.
Create new angular app
We will create a new angular app using the following command.
1 2 | ng new myapp cd myapp |
ng generate component
first, open the command prompt or terminal and create the component using the below command.
1 | ng generate component home |
You can also execute the following command.
1 | ng g c home |
The above command will generate 4 files in the “src/app” directory.
1 2 3 4 | src/app/home/home.component.ts src/app/home/home.component.html src/app/home/home.component.css src/app/home/home.component.spec.ts |
If want to add code or write edit some code in these 4 files then you can do that. when are you create the component using the command line then that component automatically added in the app.module.ts file.