Posts

Showing posts from September, 2022

Angular Project structure and default component

Image
In my  previous   blog we learnt how to setup angular project and run default app which created by angular cli. In this blog we will learn how to set up own home page and routing. Before this lets have a look on project structure : above project structure is being created by default when we create angular app . There are many folders and files but since we are in very begining stage so we will focus only  src  folder. When you expand the  src  folder you will see below folder and files : Lets expand src->app folder and understand this : in app folder we have : 1. app-routing.module.ts : it handles routing for app ,for now we need to have little knowledge of this module ,later we will learn in details. In angular we create components like *.component.html -for our template file and *.component.ts for our typescript file. Since our focus is more on practical so I am not going in details about these. If you want you can follow the angular site. So when we need to add any template file(

Bootstrap in angular project

Image
  In this tutorial I will show how to add bootstrap in angular project to and will be using bootstrap css in further tutorial.  There are different ways through which bootstrap can be referenced in our angular project 1. Installing Bootstrap from npm using the  npm install  command,  2 .Downloading Bootstrap files and adding them to the  src/assets    3. Using Bootstrap from a CDN Installing Bootstrap from npm using the  npm install  command  : open new terminal->and type “ npm install –save bootstrap ” . by this command latest bootstrap version will be added inside  node_modules/bootstrap  , also package reference will be added inside  package.json  file , apart from this you need to install jQuery by below commands: 1 npm install --save jquery after installing of above two we need to tell angular cli from where bootstrap referenced should be taken , to do this open  angular.json  file and add as below : also in  index.html  page we can add reference of bootstrap file : 1 2 3 4 5 6

Create Reactive form in angular

Image
  In angular we can create two types of forms 1. Reactive form 2.template based form In Reactive form  : all the codes handle in type script , no need to use ngModel to get and set value in control. we define form and formcontrolname for each control , and through formControl we get and set value .reactive form code is neat and clean when we have more complex structure or validation we should use reactive form . Template driven  : data binding is done via ngModel ,generally we can use this approach for simple form ,in this approach code became messy and very difficult to manage . Also in this approach difficult to handle all validation ,need more coding. So , I like to go with Reactive form approach instead of Template based. In our tutorial all forms will be reactive , but we can use both approach if required. I am going to create employee form which will have below fields : Employee Id ,Employee Name, email Id,Mobile Number,Password etc.. our final output will be as below : Employee