Creating a Component
Learn how to create a new component.
We'll cover the following
Components can be generated with the Angular CLI. While not mandatory, creating a component using the CLI can save a lot of time. It will save us the trouble of having to create the necessary files and configure the component. We can create a component with the ng generate component <name>
command. We’ll use this command to create a Post
component.
ng generate component post
This will generate the four files necessary for a component. In the src/app
directory, there will be a new directory, called post
, with four files called post.component.ts
, post.component.html
, post.component.css
, and post.component.spec.ts
.
Get hands-on with 1200+ tech skills courses.