Angular component and routing

  In my previous tutorial we learnt basics about component .In this tutorial we are going to create first component and will see how it can be added in routing and modules component.

To create new component in our project : open vs code and in terminal type below command : ng g c “your component path/component name”. I am going to create component called employee which will used in our further tutorial. so my command will be ng g c employee and hit enter.

inside the app folder - employee folder is created and employee folder contains four files as below , same time cli adds reference of the new component in app.module.ts .

created component

app.module.ts

open app-routing.module.ts type below code:const routes: Routes = [  {          path: ”,      component: EmployeeComponent,  }];

 path: ” used for default routing. will understand routing in separate lesson . so now if save and refresh my browser my employee component should be loaded first. but wait a minute , I have defined routing but in order to load this component we need to defined routing outlet in our app.component.html ..other wise employee component will not be loaded. so in app.component.html file type add below :

<router-outlet>  </router-outlet> all the components will be loaded inside this container.

And here we load our first employee component..

thats it. In next lesson we will learn how to design form using bootstrap.

Comments

Popular posts from this blog

Angular Project structure and default component

Create Reactive form in angular

Create Angular project step by step