Create Angular Components

In our previous article, we set up our development environment and created our first Angular application. Clearly, Angular CLI is a genie for the developers – you just have to give a command and it will create whatever you need.

Components are the basic building blocks of an Angular application. Let’s quickly create an Angular component.

Step 1

Inside the App folder, create a Components folder, then use the following command on integrated terminal:

ng g component components/demo

Angular Components

We can check, Angular CLI has created a demo component.

Angular Components

demo.component.ts

Angular Components

demo.component.html

Angular Components

Also, CLI will add and declare the same in the app.module.ts file.

Angular Components

Step 2

Add the demo component to the app.component.html.

We just have to add the selector of demo component as a tag where we want to include that.

Angular Components

Step 3

Run the application. Use command - 

npm start


Angular Components

As we can see, we have successfully inserted the demo component into our app component.


Similar Articles