5. Create own component. Tutorial - 5

 It's very easy to create your own component.

Basically, two ways we can create our own components.

  1. Manual
  2. Autometic with CLI command
Manual

Step 1: Create a new folder inside app folder. Follow the naming convention of a folder. Give the folder name as the module name. Like - login.

Step 2: Create your own .ts file, .html file, and .css file inside your 'login' folder. Here also follow the naming convention. 

    • login.component.ts      > Add your selector
    • login.component.html  > Write your HTML code here for your own component.
    • login.component.css    > Write here CSS code for your own HTML file.

Step 3: Add your type script(login.component.ts) class in the app.module.ts


Step 4: Lastly, add your selector which you created in login.component.ts file with another HTML file. Like - app.component.html




Step 5: All processes are done. Now check in the browser.


Automatic with CLI command

Step 1: Open the terminal and run the below command.
ng generate component home
or
ng g c home


After running the command. Angular will create components automatically and also it will add your component to 'app.module.ts' file.

Post a Comment

0 Comments