Angular 3 - Angular Components


Angular Components







Angular Component is the key feature of Angular application. We can reduce complexity of whole application by building it by using components. Because Angular components can be reused within the application.


There are two ways to create an Angular Component.Those methods are create component manually or creating component directly by using angular command.

 Method 01

In this method we create files manually which are included in a component. As a example lets create a new header component.

  • first create a header folder inside the app folder.
  • After that create header.component.html file , header.component.css file and header.component.ts file inside the header folder.

  • Type the content which you want to show in the header in header.html file.
  • import component from angular core in header.component.ts file as below image.and use a selector with app prefix and put location of header.component.html file as template url.

  • After that include export class under the Ngmodules declarations array which is in the appmodule.ts file and import Header component as below image.



  • include selector tags in app.component.html .


  • After that run ng serve command and type localhost:4200 on a browser.It will give you output like below.





Method 02

  • By using following commands we can generate component directly.
  • ng generate component component_name or ng g c component_name .

Comments

Popular posts from this blog

Angular 6 - Data Binding Part 2

Machine Learning

Selenium - 1