Author: therichpost

  • Angular material data table working example

    Angular material data table working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular material data table working example.

    Guys here is the update post for Angular 11 :


    Angular material data table working example
    Angular material data table working example

    Here are the working steps and please follow carefully:

    1. Here are the basics commands to install angular 8 on your system:

    npm install -g @angular/cli 
    
    ng new angularpopup //Create new Angular Project
    
    $ cd angularpopup // Go inside the Angular Project Folder
    
    ng serve --open // Run and Open the Angular Project
    
    http://localhost:4200/ // Working Angular Project Url

     

    2. After done with above, you need to run below command to add @angular/material into your angular 8 application:

    ng add @angular/material

     

    3. Now you need to add below code into your src/app/app.module.ts file:

    ...
    import {  MatTableModule } from '@angular/material/table';
    import {  MatPaginatorModule } from '@angular/material/paginator';
    
    
    @NgModule({
    ...
      imports: [
      ...
        MatPaginatorModule,
        MatTableModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    4. Now you need to add below code into your src/app/app.component.ts file:

    import { Component, OnInit, ViewChild } from '@angular/core';
    import {MatPaginator} from '@angular/material/paginator';
    import {MatTableDataSource} from '@angular/material/table';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
      dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
    
      @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
    
      ngOnInit() {
        this.dataSource.paginator = this.paginator;
      }
      title = 'paginator';
    }
    export interface PeriodicElement {
      name: string;
      position: number;
      weight: number;
      symbol: string;
    }
    const ELEMENT_DATA: PeriodicElement[] = [
      {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
      {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
      {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
      {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
      {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
      {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
      {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
      {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
      {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
      {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
      {position: 11, name: 'Sodium', weight: 22.9897, symbol: 'Na'},
      {position: 12, name: 'Magnesium', weight: 24.305, symbol: 'Mg'},
      {position: 13, name: 'Aluminum', weight: 26.9815, symbol: 'Al'},
      {position: 14, name: 'Silicon', weight: 28.0855, symbol: 'Si'},
      {position: 15, name: 'Phosphorus', weight: 30.9738, symbol: 'P'},
      {position: 16, name: 'Sulfur', weight: 32.065, symbol: 'S'},
      {position: 17, name: 'Chlorine', weight: 35.453, symbol: 'Cl'},
      {position: 18, name: 'Argon', weight: 39.948, symbol: 'Ar'},
      {position: 19, name: 'Potassium', weight: 39.0983, symbol: 'K'},
      {position: 20, name: 'Calcium', weight: 40.078, symbol: 'Ca'},
    ];

     

    5. Now you need to add below code into src/app/app.component.html file:

    <div class="mat-elevation-z8">
      <table mat-table [dataSource]="dataSource">
    
        <!-- Position Column -->
        <ng-container matColumnDef="position">
          <th mat-header-cell *matHeaderCellDef> No. </th>
          <td mat-cell *matCellDef="let element"> {{element.position}} </td>
        </ng-container>
    
        <!-- Name Column -->
        <ng-container matColumnDef="name">
          <th mat-header-cell *matHeaderCellDef> Name </th>
          <td mat-cell *matCellDef="let element"> {{element.name}} </td>
        </ng-container>
    
        <!-- Weight Column -->
        <ng-container matColumnDef="weight">
          <th mat-header-cell *matHeaderCellDef> Weight </th>
          <td mat-cell *matCellDef="let element"> {{element.weight}} </td>
        </ng-container>
    
        <!-- Symbol Column -->
        <ng-container matColumnDef="symbol">
          <th mat-header-cell *matHeaderCellDef> Symbol </th>
          <td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
        </ng-container>
    
        <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
        <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
      </table>
    
      <mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
    </div>
    

     

    6. Now you need to add below code into src/app/app.component.css file:

    table {
        width: 100%;
      }

     

    In the end, don’t forgot to run ng serve command. If you have any query then do comment below.

    Jassa

    Thank you.

  • Chinese dor should be banned in ludhiana punjab

    Chinese dor should be banned in ludhiana punjab

    Hello to all, welcome to therichpost.com. Today in this post, I came with very serious topic Chinese dor.

    Now here is Lohri festival season and In india Lohri festival also called festival of kites. In my childhood me and my friend used to had flown kites with simple and manjha dor and that dor was not harmful to anybody but now chinese dor came in market and chinese dor is very harmful to all living beings and every year many living beings injure and died with chinese dor. So I personally request to all the shopkeepers of ludhiana that please stop sell chinese dor and save lives of many living beings.

    How living beings die with chinese dor?

    when chinese dor stick to any living beings then chinese dor does not break easily and it stretches itself. last year I also injured for it.

    Here are the proof with some images which I have collected from google and please be brave to see this:

    Images source is google:

    chinese dor stuck in man neck during driving
    chinese dor stuck around to flying bird

    So I humbly request to all the shopkeepers of ludhiana that please stop sell chinese dor and also to ludhiana police that please take action to those shopkeepers who sells chinese dor.

    Merry christmas and Happy new year and Happy lohri in advance.

    Thank you

  • Angular datatables with custom button event click open bootstrap modal popup

    Angular datatables with custom button event click open bootstrap modal popup

    Hello to all, welcome to therichpost.com In this post, I will tell you, Angular datatables with custom button event click open bootstrap modal popup.

    This post first part : Angular datatable with print csv excel copy buttons

    anhular datatable
    Angular datatables with custom button event click open bootstrap modal popup
    angular datatable
    Angular datatables with custom button event click open bootstrap modal popup

    Post Working

    In this post, I am adding custom button(details) in my datatable and when I will click on that button then I will get the popup with user details.
    To all this action perform, I used jquery and bootstrap also.

    Here are complete steps and please follow carefully:

    1. Here are the basics commands to install angular 8 on your system:

    npm install -g @angular/cli 
    
    ng new angularpopup //Create new Angular Project
    
    $ cd angularpopup // Go inside the Angular Project Folder
    
    ng serve --open // Run and Open the Angular Project
    
    http://localhost:4200/ // Working Angular Project Url

     

    2. After done with above, you need to run below commands to set bootstrap, datatable, jquery environment into your angular 8 application:

    npm install jquery --save
    npm install datatables.net --save
    npm install datatables.net-dt --save
    npm install angular-datatables --save
    npm install @types/jquery --save-dev
    npm install @types/datatables.net --save-dev
    npm install ngx-bootstrap bootstrap --save
    npm install datatables.net-buttons --save
    npm install datatables.net-buttons-dt --save
    npm install @types/datatables.net-buttons --save-dev
    npm install jszip --save
                

     

    3. Now you need to add below code into your angular.json file:

    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/datatables.net-dt/css/jquery.dataTables.css",
                  "node_modules/bootstrap/dist/css/bootstrap.min.css",
                ],
    "scripts": [
                "node_modules/jquery/dist/jquery.js",
                "node_modules/datatables.net/js/jquery.dataTables.js",
                "node_modules/bootstrap/dist/js/bootstrap.js",
                "node_modules/jszip/dist/jszip.js",
                "node_modules/datatables.net-buttons/js/dataTables.buttons.js",
                "node_modules/datatables.net-buttons/js/buttons.colVis.js",
                "node_modules/datatables.net-buttons/js/buttons.flash.js",
                "node_modules/datatables.net-buttons/js/buttons.html5.js",
                "node_modules/datatables.net-buttons/js/buttons.print.js"
               
                ]
    ...

     

    4. Now you need to add below code into your src/app/app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import {DataTablesModule} from 'angular-datatables';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        DataTablesModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    4. Now you need to add below code into your src/app/app.component.ts file:

    import { Component, OnInit } from '@angular/core';
    declare var $: any 
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      public data = [
        {name: 'Ajay', email: 'test@gmail.com', website:'test.com'},
        {name: 'Alisha', email: 'test@gmail.com', website:'test.com'},
        {name: 'Jassa', email: 'test@gmail.com', website:'test.com'},
        {name: 'Jas', email: 'test@gmail.com', website:'test.com'},
    ];
    
      title = 'angulardatatables';
      dtOptions: any = {};
      ngOnInit() {
        this.dtOptions = {
          pagingType: 'full_numbers',
          pageLength: 3,
          processing: true,
          dom: 'Bfrtip',
            buttons: [
                'copy', 'csv', 'excel', 'print'
            ]
        };
       $(document).on( 'click', '.getDetails', function () {
          $(".username").text("");
          $(".username").text($(this).parents("tr").find(".fname").text());
         $("#myModal").modal('show');
      } );
    }
    }

     

    5. Now you need to add below code into src/app/app.component.html file:

    <table class="table table-striped table-bordered table-sm row-border hover" datatable [dtOptions]="dtOptions">
      <thead>
        <tr>
          <th>Name</th>
          <th>Email</th>
          <th>Website</th>
        <th>Details</th>
        </tr>
      </thead>
      <tbody>
       <tr *ngFor="let group of data">
             <td class="fname">{{group.name}}</td>
             <td>{{group.email}}</td>
             <td>{{group.website}}</td>
         <td><button class="getDetails">Details</button></td>
         </tr>
      </tbody>
    </table>
    
    <!-- The Modal -->
    <div class="modal" id="myModal">
      <div class="modal-dialog">
        <div class="modal-content">
        
          <!-- Modal Header -->
          <div class="modal-header">
            <h4 class="modal-title">User Name</h4>
            <button type="button" class="close" data-dismiss="modal">&times;</button>
          </div>
          
          <!-- Modal body -->
          <div class="modal-body">
            Hi : <span class="username"></span>
          </div>
          
          <!-- Modal footer -->
          <div class="modal-footer">
            <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
          </div>
          
        </div>
      </div>
    </div>
    

     

    In the end, don’t forgot to run ng serve command. If you have any query then do comment below. In next part of this post, I will get the dynamic data and show in datatable with angular httpclient.

    Jassa

    Thank you.

  • How to get image from laravel and show in angular?

    How to get image from laravel and show in angular?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to get image from laravel and show in angular?

    This is the first part of How to upload image with Laravel Angular?

    Post Working

    In this post, I am getting image from laravel backend and with angular httpclient, I am showing that image in my angular 8 application. For laravel setup, I have used xampp.

    Here are the working steps and please follow carefully:

    1. Very first, you need to run common below commands to add Angular 8 project on your machine:

    $ npm install -g @angular/cli
    
    $ ng new angularlaraveluploadimage //Install fresh Angular setup
    
    $ cd angularlaraveluploadimage //go inside angular fresh setup

    2. Now you need to add the below code into your src\app\app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { HttpClientModule } from '@angular/common/http';
    import { AppComponent } from './app.component';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        HttpClientModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    3. Now you need to add below code into your Angular 8 src\app\app.component.ts file:

    import { Component } from '@angular/core';
    import { HttpClient} from '@angular/common/http';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      data:any;
      constructor(private http: HttpClient) {
      
        this.http.get('http://localhost/blog/public/api/sample-restful-apis').subscribe(data => {
            this.data = data;
            console.log(this.data);
            }, error => console.error(error));
        }
            
          
    }
    

    4. Now you need to add into your Angular 8 app.component.html file:

    <img src="{{data}}">

    Laravel Code

    1. Here is the code for your laravel 6 routes/api.php file:

    Route::get('/sample-restful-apis','HomeController@getData');

    2. Now you need to all below code into app\Http\Controllers\HomeController.php file:

    public function getData()
        {
             $imgsrc = "https://secure.gravatar.com/avatar/d09eaad01aea86c51b4f892b4f8abf6f?s=100&d=wavatar&r=g";
            return response()->json($imgsrc);
        }

    This is it and if you have any query regarding this post then please do comment below.

    Jassa

    Thank you

  • How to implement select2 in angular 8?

    How to implement select2 in angular 8?

    Hello guys, welcome to therichpost.com. In this post, I will tell you, How to Implement Select2 in Angular 8?

    I was sitting and thinking and suddenly an Idea came to my mind and I wrote new post related select2 implementation in Angular 8.

    Select2 is very well customize select box with searching, sorting, autocomplete and many more features.

    Here is the working picture:

    How to Implement Select2 in Angular 7?

    Here are the working coding steps:

    1. Very first, you need to run common below commands to add Angular 8 project on your machine:
    $ npm install -g @angular/cli 
    
    $ ng new angularselect2 //Install Angular Project
    
    $ cd angularselect2 // Go to project folder
    
    $ ng serve //Run Project
    
    http://localhost:4200/ //Run On local server
    2. Now you need to run below commands to add select2 and jquery into your Angular application:
    npm install select2
    
    npm install jquery --save
    3. Now add below code into your angular.json file:
    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/select2/dist/css/select2.min.css", 
                  "node_modules/select2/dist/js/select2.min.js" // I added here because this is not working in script block
              ],
    "scripts":[
                  "node_modules/jquery/dist/jquery.js"
              ]
    ...
    4. Now add below code into your app.component.ts file:
    import { Component, OnInit } from '@angular/core';
    import * as jquery from 'jquery';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angularselect2';
    
      ngOnInit()
      {
           jquery('.js-example-basic-single').select2(); //initialize select2 to particular input
      }
    }
    5. Finally add below code into your app.component.html file:
    <div style="text-align:center">
      <h1>
        Welcome to {{ title }}!
      </h1>
      <select class="js-example-basic-single" name="state" style="width: 150px;">
      <option value="AL">Alabama</option>
      <option value="WY">Wyoming</option>
    </select>
    </div>

    This is it. If you have any query related to this post then do comment below or you can ask questions.

    Thank you,

    Jassa,

    TheRichPost.

    Notes: I have this blog for helping others and everyone can ask me queries related to Angular, Laravel, WordPress etc. I will be very happy to help all.

  • Open bootstrap modal pop on datatable row click event

    Open bootstrap modal pop on datatable row click event

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Open bootstrap modal pop on datatable row click event.

    Open bootstrap modal pop on datatable row click event
    Open bootstrap modal pop on datatable row click event

    Post Information:-

    In this post, I have used Datatable, jQuery, Bootstrap. On datatable row click event, I am opening bootstrap modal popup with that row details.

    Here is the working code and you can add into your html file or your any project:

    <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
            <tr>
                <td>Ashton Cox</td>
                <td>Junior Technical Author</td>
                <td>San Francisco</td>
                <td>66</td>
                <td>2009/01/12</td>
                <td>$86,000</td>
            </tr>
            <tr>
                <td>Cedric Kelly</td>
                <td>Senior Javascript Developer</td>
                <td>Edinburgh</td>
                <td>22</td>
                <td>2012/03/29</td>
                <td>$433,060</td>
            </tr>
            <tr>
                <td>Airi Satou</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>33</td>
                <td>2008/11/28</td>
                <td>$162,700</td>
            </tr>
            <tr>
                <td>Brielle Williamson</td>
                <td>Integration Specialist</td>
                <td>New York</td>
                <td>61</td>
                <td>2012/12/02</td>
                <td>$372,000</td>
            </tr>
            <tr>
                <td>Herrod Chandler</td>
                <td>Sales Assistant</td>
                <td>San Francisco</td>
                <td>59</td>
                <td>2012/08/06</td>
                <td>$137,500</td>
            </tr>
            <tr>
                <td>Rhona Davidson</td>
                <td>Integration Specialist</td>
                <td>Tokyo</td>
                <td>55</td>
                <td>2010/10/14</td>
                <td>$327,900</td>
            </tr>
            <tr>
                <td>Colleen Hurst</td>
                <td>Javascript Developer</td>
                <td>San Francisco</td>
                <td>39</td>
                <td>2009/09/15</td>
                <td>$205,500</td>
            </tr>
            <tr>
                <td>Sonya Frost</td>
                <td>Software Engineer</td>
                <td>Edinburgh</td>
                <td>23</td>
                <td>2008/12/13</td>
                <td>$103,600</td>
            </tr>
            <tr>
                <td>Jena Gaines</td>
                <td>Office Manager</td>
                <td>London</td>
                <td>30</td>
                <td>2008/12/19</td>
                <td>$90,560</td>
            </tr>
            <tr>
                <td>Quinn Flynn</td>
                <td>Support Lead</td>
                <td>Edinburgh</td>
                <td>22</td>
                <td>2013/03/03</td>
                <td>$342,000</td>
            </tr>
            <tr>
                <td>Charde Marshall</td>
                <td>Regional Director</td>
                <td>San Francisco</td>
                <td>36</td>
                <td>2008/10/16</td>
                <td>$470,600</td>
            </tr>
            <tr>
                <td>Haley Kennedy</td>
                <td>Senior Marketing Designer</td>
                <td>London</td>
                <td>43</td>
                <td>2012/12/18</td>
                <td>$313,500</td>
            </tr>
            <tr>
                <td>Tatyana Fitzpatrick</td>
                <td>Regional Director</td>
                <td>London</td>
                <td>19</td>
                <td>2010/03/17</td>
                <td>$385,750</td>
            </tr>
            <tr>
                <td>Michael Silva</td>
                <td>Marketing Designer</td>
                <td>London</td>
                <td>66</td>
                <td>2012/11/27</td>
                <td>$198,500</td>
            </tr>
            <tr>
                <td>Paul Byrd</td>
                <td>Chief Financial Officer (CFO)</td>
                <td>New York</td>
                <td>64</td>
                <td>2010/06/09</td>
                <td>$725,000</td>
            </tr>
            <tr>
                <td>Gloria Little</td>
                <td>Systems Administrator</td>
                <td>New York</td>
                <td>59</td>
                <td>2009/04/10</td>
                <td>$237,500</td>
            </tr>
            <tr>
                <td>Bradley Greer</td>
                <td>Software Engineer</td>
                <td>London</td>
                <td>41</td>
                <td>2012/10/13</td>
                <td>$132,000</td>
            </tr>
            <tr>
                <td>Dai Rios</td>
                <td>Personnel Lead</td>
                <td>Edinburgh</td>
                <td>35</td>
                <td>2012/09/26</td>
                <td>$217,500</td>
            </tr>
            <tr>
                <td>Jenette Caldwell</td>
                <td>Development Lead</td>
                <td>New York</td>
                <td>30</td>
                <td>2011/09/03</td>
                <td>$345,000</td>
            </tr>
            <tr>
                <td>Yuri Berry</td>
                <td>Chief Marketing Officer (CMO)</td>
                <td>New York</td>
                <td>40</td>
                <td>2009/06/25</td>
                <td>$675,000</td>
            </tr>
            <tr>
                <td>Caesar Vance</td>
                <td>Pre-Sales Support</td>
                <td>New York</td>
                <td>21</td>
                <td>2011/12/12</td>
                <td>$106,450</td>
            </tr>
            <tr>
                <td>Doris Wilder</td>
                <td>Sales Assistant</td>
                <td>Sidney</td>
                <td>23</td>
                <td>2010/09/20</td>
                <td>$85,600</td>
            </tr>
            <tr>
                <td>Angelica Ramos</td>
                <td>Chief Executive Officer (CEO)</td>
                <td>London</td>
                <td>47</td>
                <td>2009/10/09</td>
                <td>$1,200,000</td>
            </tr>
            <tr>
                <td>Gavin Joyce</td>
                <td>Developer</td>
                <td>Edinburgh</td>
                <td>42</td>
                <td>2010/12/22</td>
                <td>$92,575</td>
            </tr>
            <tr>
                <td>Jennifer Chang</td>
                <td>Regional Director</td>
                <td>Singapore</td>
                <td>28</td>
                <td>2010/11/14</td>
                <td>$357,650</td>
            </tr>
            <tr>
                <td>Brenden Wagner</td>
                <td>Software Engineer</td>
                <td>San Francisco</td>
                <td>28</td>
                <td>2011/06/07</td>
                <td>$206,850</td>
            </tr>
            <tr>
                <td>Fiona Green</td>
                <td>Chief Operating Officer (COO)</td>
                <td>San Francisco</td>
                <td>48</td>
                <td>2010/03/11</td>
                <td>$850,000</td>
            </tr>
            <tr>
                <td>Shou Itou</td>
                <td>Regional Marketing</td>
                <td>Tokyo</td>
                <td>20</td>
                <td>2011/08/14</td>
                <td>$163,000</td>
            </tr>
            <tr>
                <td>Michelle House</td>
                <td>Integration Specialist</td>
                <td>Sidney</td>
                <td>37</td>
                <td>2011/06/02</td>
                <td>$95,400</td>
            </tr>
            <tr>
                <td>Suki Burks</td>
                <td>Developer</td>
                <td>London</td>
                <td>53</td>
                <td>2009/10/22</td>
                <td>$114,500</td>
            </tr>
            <tr>
                <td>Prescott Bartlett</td>
                <td>Technical Author</td>
                <td>London</td>
                <td>27</td>
                <td>2011/05/07</td>
                <td>$145,000</td>
            </tr>
            <tr>
                <td>Gavin Cortez</td>
                <td>Team Leader</td>
                <td>San Francisco</td>
                <td>22</td>
                <td>2008/10/26</td>
                <td>$235,500</td>
            </tr>
            <tr>
                <td>Martena Mccray</td>
                <td>Post-Sales support</td>
                <td>Edinburgh</td>
                <td>46</td>
                <td>2011/03/09</td>
                <td>$324,050</td>
            </tr>
            <tr>
                <td>Unity Butler</td>
                <td>Marketing Designer</td>
                <td>San Francisco</td>
                <td>47</td>
                <td>2009/12/09</td>
                <td>$85,675</td>
            </tr>
            <tr>
                <td>Howard Hatfield</td>
                <td>Office Manager</td>
                <td>San Francisco</td>
                <td>51</td>
                <td>2008/12/16</td>
                <td>$164,500</td>
            </tr>
            <tr>
                <td>Hope Fuentes</td>
                <td>Secretary</td>
                <td>San Francisco</td>
                <td>41</td>
                <td>2010/02/12</td>
                <td>$109,850</td>
            </tr>
            <tr>
                <td>Vivian Harrell</td>
                <td>Financial Controller</td>
                <td>San Francisco</td>
                <td>62</td>
                <td>2009/02/14</td>
                <td>$452,500</td>
            </tr>
            <tr>
                <td>Timothy Mooney</td>
                <td>Office Manager</td>
                <td>London</td>
                <td>37</td>
                <td>2008/12/11</td>
                <td>$136,200</td>
            </tr>
            <tr>
                <td>Jackson Bradshaw</td>
                <td>Director</td>
                <td>New York</td>
                <td>65</td>
                <td>2008/09/26</td>
                <td>$645,750</td>
            </tr>
            <tr>
                <td>Olivia Liang</td>
                <td>Support Engineer</td>
                <td>Singapore</td>
                <td>64</td>
                <td>2011/02/03</td>
                <td>$234,500</td>
            </tr>
            <tr>
                <td>Bruno Nash</td>
                <td>Software Engineer</td>
                <td>London</td>
                <td>38</td>
                <td>2011/05/03</td>
                <td>$163,500</td>
            </tr>
            <tr>
                <td>Sakura Yamamoto</td>
                <td>Support Engineer</td>
                <td>Tokyo</td>
                <td>37</td>
                <td>2009/08/19</td>
                <td>$139,575</td>
            </tr>
            <tr>
                <td>Thor Walton</td>
                <td>Developer</td>
                <td>New York</td>
                <td>61</td>
                <td>2013/08/11</td>
                <td>$98,540</td>
            </tr>
            <tr>
                <td>Finn Camacho</td>
                <td>Support Engineer</td>
                <td>San Francisco</td>
                <td>47</td>
                <td>2009/07/07</td>
                <td>$87,500</td>
            </tr>
            <tr>
                <td>Serge Baldwin</td>
                <td>Data Coordinator</td>
                <td>Singapore</td>
                <td>64</td>
                <td>2012/04/09</td>
                <td>$138,575</td>
            </tr>
            <tr>
                <td>Zenaida Frank</td>
                <td>Software Engineer</td>
                <td>New York</td>
                <td>63</td>
                <td>2010/01/04</td>
                <td>$125,250</td>
            </tr>
            <tr>
                <td>Zorita Serrano</td>
                <td>Software Engineer</td>
                <td>San Francisco</td>
                <td>56</td>
                <td>2012/06/01</td>
                <td>$115,000</td>
            </tr>
            <tr>
                <td>Jennifer Acosta</td>
                <td>Junior Javascript Developer</td>
                <td>Edinburgh</td>
                <td>43</td>
                <td>2013/02/01</td>
                <td>$75,650</td>
            </tr>
            <tr>
                <td>Cara Stevens</td>
                <td>Sales Assistant</td>
                <td>New York</td>
                <td>46</td>
                <td>2011/12/06</td>
                <td>$145,600</td>
            </tr>
            <tr>
                <td>Hermione Butler</td>
                <td>Regional Director</td>
                <td>London</td>
                <td>47</td>
                <td>2011/03/21</td>
                <td>$356,250</td>
            </tr>
            <tr>
                <td>Lael Greer</td>
                <td>Systems Administrator</td>
                <td>London</td>
                <td>21</td>
                <td>2009/02/27</td>
                <td>$103,500</td>
            </tr>
            <tr>
                <td>Jonas Alexander</td>
                <td>Developer</td>
                <td>San Francisco</td>
                <td>30</td>
                <td>2010/07/14</td>
                <td>$86,500</td>
            </tr>
            <tr>
                <td>Shad Decker</td>
                <td>Regional Director</td>
                <td>Edinburgh</td>
                <td>51</td>
                <td>2008/11/13</td>
                <td>$183,000</td>
            </tr>
            <tr>
                <td>Michael Bruce</td>
                <td>Javascript Developer</td>
                <td>Singapore</td>
                <td>29</td>
                <td>2011/06/27</td>
                <td>$183,000</td>
            </tr>
            <tr>
                <td>Donna Snider</td>
                <td>Customer Support</td>
                <td>New York</td>
                <td>27</td>
                <td>2011/01/25</td>
                <td>$112,000</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>
    <!-- Modal -->
    <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">User Details</h4>
        </div>
        <div class="modal-body">
          <div class="username"><p>Name: </p><span></span></div>
          <div class="position"><p>Position: </p><span></span></div>
          <div class="office"><p>Office: </p><span></span></div>
          <div class="age"><p>Age: </p><span></span></div>
          <div class="date"><p>Start date: </p><span></span></div>
          <div class="salary"><p>Salary: </p><span></span></div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
    </div>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
    
    <style>
        .btn-purple {
        color: #fff;
        background-color: #6f42c1;
        border-color: #643ab0;
    }
    .modal-body div{float:left; width: 100%}
    .modal-body div p{float:left; width: 20%; font-weight: 600;}
    .modal-body div span{float:left; width: 80%}
    </style>
    
    <script>
        jQuery(document).ready(function($) {
        $('#example').DataTable({
            searching: false,
            responsive: true,
            "autoWidth": false,
        });
        var table = $('#example').DataTable();
        $('#example tbody').on('click', 'tr', function () {
            //console.log(table.row(this).data());
            $(".modal-body div span").text("");
            $(".username span").text(table.row(this).data()[0]);
            $(".position span").text(table.row(this).data()[1]);
            $(".office span").text(table.row(this).data()[2]);
            $(".age span").text(table.row(this).data()[3]);
            $(".date span").text(table.row(this).data()[4]);
            $(".salary span").text(table.row(this).data()[5]);
            $("#myModal").modal("show");
        });
    } );
    </script>

     

    If you have any query related to this post then please comment below.

    Jassa

    Thank you

  • Angular 17 data table with print csv excel copy buttons

    Angular 17 data table with print csv excel copy buttons

    Hello to all, welcome to therichpost.com In this post, I will tell you, Angular 17 data table with print csv excel copy buttons.

    This post next part : Angular datatables with custom button event click open bootstrap modal popup

    Angular datatable with print csv excel copy buttons
    Angular 17 data table with print csv excel copy buttons

    Today, you see angular 8 datatables with csv, excel, copy and print buttons. I have used bootstrap also for good looks.

    Here are complete steps and please follow carefully:

    1. Here are the basics commands to install angular 8 on your system:

    npm install -g @angular/cli 
    
    ng new angularpopup //Create new Angular Project
    
    $ cd angularpopup // Go inside the Angular Project Folder
    
    ng serve --open // Run and Open the Angular Project
    
    http://localhost:4200/ // Working Angular Project Url

    2. After done with above, you need to run below commands to set bootstrap, datatable, jquery environment into your angular 8 application:

    npm install jquery --save
    npm install datatables.net --save
    npm install datatables.net-dt --save
    npm install angular-datatables --save
    npm install @types/jquery --save-dev
    npm install @types/datatables.net --save-dev
    npm install ngx-bootstrap bootstrap --save
    npm install datatables.net-buttons --save
    npm install datatables.net-buttons-dt --save
    npm install @types/datatables.net-buttons --save-dev
    npm install jszip --save
                

    3. Now you need to add below code into your angular.json file:

    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/datatables.net-dt/css/jquery.dataTables.css",
                  "node_modules/bootstrap/dist/css/bootstrap.min.css",
                ],
    "scripts": [
                "node_modules/jquery/dist/jquery.js",
                "node_modules/datatables.net/js/jquery.dataTables.js",
                "node_modules/bootstrap/dist/js/bootstrap.js",
                "node_modules/jszip/dist/jszip.js",
                "node_modules/datatables.net-buttons/js/dataTables.buttons.js",
                "node_modules/datatables.net-buttons/js/buttons.colVis.js",
                "node_modules/datatables.net-buttons/js/buttons.flash.js",
                "node_modules/datatables.net-buttons/js/buttons.html5.js",
                "node_modules/datatables.net-buttons/js/buttons.print.js"
               
                ]
    ...

    4. Now you need to add below code into your src/app/app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import {DataTablesModule} from 'angular-datatables';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        DataTablesModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    4. Now you need to add below code into your src/app/app.component.ts file:

    import { Component, OnInit } from '@angular/core';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      public data = [
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
    ];
    
      title = 'angulardatatables';
      dtOptions: any = {};
      ngOnInit() {
        this.dtOptions = {
          pagingType: 'full_numbers',
          pageLength: 3,
          processing: true,
          dom: 'Bfrtip',
            buttons: [
                'copy', 'csv', 'excel', 'print'
            ]
        };
    }
    }

    5. Now you need to add below code into src/app/app.component.html file:

    <table class="table table-striped table-bordered table-sm row-border hover" datatable [dtOptions]="dtOptions">
      <thead>
        <tr>
          <th>Name</th>
          <th>Email</th>
          <th>Website</th>
        </tr>
      </thead>
      <tbody>
       <tr *ngFor="let group of data">
             <td>{{group.name}}</td>
             <td>{{group.email}}</td>
             <td>{{group.website}}</td>
         </tr>
      </tbody>
    </table>

    In the end, don’t forgot to run ng serve command. If you have any query then do comment below.

    Jassa

    Thank you.

  • Angular 8 fullcalendar event tooltip

    Angular 8 fullcalendar event tooltip

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 8 fullcalendar event tooltip.

    angular 8 bootstrap tooltip on fullcalendar event hover
    angular 8 bootstrap tooltip on fullcalendar event hover

    In Angular, I will show, bootstrap tooltip on fullcalendar event hover with the help of jquery.

    Here are the complete steps and please follow carefully:

    1. Here are the basics commands to install angular 8 on your system:

    npm install -g @angular/cli 
    
    ng new angularpopup //Create new Angular Project
    
    $ cd angularpopup // Go inside the Angular Project Folder
    
    ng serve --open // Run and Open the Angular Project
    
    http://localhost:4200/ // Working Angular Project Url

    2. After done with above, you need to run below commands to set bootstrap, fullcalendar, jquery environment into your angular 8 application:

    npm install --save bootstrap
    
    npm i fullcalendar //Add fullcalendar module
    
    npm i moment //Add momentjs library
    
    npm install jquery --save
    
    npm install --save @types/jquery
    
    npm install popper.js --save

    3. Now you need to add below code into your angular.json file:

    "styles": [
                "src/styles.css",
                "node_modules/fullcalendar/dist/fullcalendar.min.css",
                "node_modules/bootstrap/dist/css/bootstrap.min.css"
              ],
    "scripts": ["node_modules/jquery/dist/jquery.min.js",
                "node_modules/popper.js/dist/umd/popper.min.js",
                "node_modules/bootstrap/dist/js/bootstrap.min.js",
                "node_modules/moment/min/moment.min.js", 
                "node_modules/fullcalendar/dist/fullcalendar.min.js"]

    4. Now you need to add below code into your src/app/app.component.ts file:

    import { Component } from '@angular/core';
    declare var $: any;
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'easyfullcalendar';
    
    ngOnInit(){
      
           setTimeout(() => {
           
            $("#calendar").fullCalendar({  
                            header: {
                                left   : 'prev,next today',
                                center : 'title',
                                right  : 'month,agendaWeek,agendaDay'
                            },
                            navLinks   : true,
                            editable   : true,
                            eventLimit : true,
                            eventRender: function(event, element, view) {
                              element.find('span.fc-title').attr('data-toggle', 'tooltip');  
                              element.find('span.fc-title').attr('title', event.title);   
                           },
                            events: [
                              {
                                title: 'All Day Event',
                                description: 'description for All Day Event',
                                start: '2019-12-01'
                              },
                              {
                                title: 'Long Event',
                                description: 'description for Long Event',
                                start: '2019-12-07',
                                end: '2019-12-10'
                              },
                              {
                                groupId: '999',
                                title: 'Repeating Event',
                                description: 'description for Repeating Event',
                                start: '2019-12-09T16:00:00'
                              },
                              {
                                groupId: '999',
                                title: 'Repeating Event',
                                description: 'description for Repeating Event',
                                start: '2019-12-16T16:00:00'
                              },
                              {
                                title: 'Conference',
                                description: 'description for Conference',
                                start: '2019-12-11',
                                end: '2019-12-13'
                              },
                              {
                                title: 'Meeting',
                                description: 'description for Meeting',
                                start: '2019-12-12T10:30:00',
                                end: '2019-12-12T12:30:00'
                              },
                              {
                                title: 'Lunch',
                                description: 'description for Lunch',
                                start: '2019-12-12T12:00:00'
                              },
                              {
                                title: 'Meeting',
                                description: 'description for Meeting',
                                start: '2019-12-12T14:30:00'
                              },
                              {
                                title: 'Birthday Party',
                                description: 'description for Birthday Party',
                                start: '2019-12-13T07:00:00'
                              },
                              {
                                title: 'Click for Google',
                                description: 'description for Click for Google',
                                url: 'http://google.com/',
                                start: '2019-12-28'
                              }
                            ]  // request to load current events
                        }).on('click', '.fc-agendaWeek-button, .fc-month-button, .fc-agendaDay-button, .fc-prev-button, .fc-next-button', function() {
       $('[data-toggle="tooltip"]').tooltip();
    });
                        $('[data-toggle="tooltip"]').tooltip();
         }, 100);
       }
    }

    5. Now you need to add below code into src/app/app.component.html file:

    <div id="calendar"></div>

    In the end, don’t forgot to run ng serve command. If you have any query then do comment below.

    Jassa

    Thank you.

  • Angular 8 with php tutorial part 2

    Angular 8 with php tutorial part 2

    Hello to all, welcome to therichpost.com. In this post, I will continue with Angular 8 with php tutorial part 2.

    Here you can check the part 1 of this post : Angular 8 with php tutorial.

    In this post, I will save the angular form data into php mysql database with the help of angular HttpClient.

    Angular 8 with php tutorial part 2
    Angular 8 with php tutorial part 2

    Here are the complete code snippets and please follow carefully:

    1. Here are the basics commands to install angular 8 on your system:

    npm install -g @angular/cli 
    
    ng new angularpopup //Create new Angular Project
    
    cd angularpopup // Go inside the Angular Project Folder
    
    ng serve --open // Run and Open the Angular Project
    
    http://localhost:4200/ // Working Angular Project Url

     

    2. After done with above, you need to run below commands to set bootstrap environment into your angular 8 application:

    npm install --save bootstrap

     

    3. Now you need to add below code into your angular.json file:

    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/bootstrap/dist/css/bootstrap.min.css"
              ],
    "scripts": ["node_modules/bootstrap/dist/js/bootstrap.min.js"]
    ...

     

    4. Now you need to add below code into your src/app/app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import { ReactiveFormsModule } from '@angular/forms';
    import { HttpClientModule } from '@angular/common/http';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        ReactiveFormsModule,
      HttpClientModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

     

    5. Now you need to add below code into your src/app/app.component.ts file:

    import { Component } from '@angular/core';
    import { FormBuilder, FormGroup, Validators } from '@angular/forms';
    import { HttpClient, HttpParams } from '@angular/common/http';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      registerForm: FormGroup;
      submitted = false;
      posts: any;
      constructor(private formBuilder: FormBuilder, private http: HttpClient) { }
      ngOnInit() {
        this.registerForm = this.formBuilder.group({
            email: ['', [Validators.required, Validators.email]],
            password: ['', [Validators.required, Validators.minLength(6)]],
            firstname: ['', [Validators.required, Validators.minLength(6)]],
            mobile: ['', [Validators.required, Validators.pattern(/^-?(0|[1-9]\d*)?$/), Validators.minLength(10)]]
        });
    }
    // convenience getter for easy access to form fields
    get f() { return this.registerForm.controls; }
    onSubmit() {
        this.submitted = true;
        // stop here if form is invalid
        if (this.registerForm.invalid) {
            return;
        }
        if(this.submitted)
        {
          // Initialize Params Object
           const params = new HttpParams({
              fromObject: {
                firstname: this.registerForm.value.firstname,
                password: this.registerForm.value.password,
                mobile: this.registerForm.value.mobile,
                email: this.registerForm.value.email,
              }
            });
        
        return this.http.post('http://localhost/mypage.php', params).subscribe(data => {
          this.posts = data;
          // show data in console
          console.log(this.posts);
          });
        }
    }
    }

     

    6. Now you need to add below code into src/app/app.component.html file:

    <div class="container">
          <h1 class="text-center">Angular 8 with php tutorial part 2</h1>
        <form [formGroup]="registerForm" (ngSubmit)="onSubmit()">
                            <div class="row">
                               <div class="col-sm-6">
                                  <div class="form-group">
                                        <label>FirstName</label>
                                        <input type="text" formControlName="firstname" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.firstname.errors }" />
                                        <div *ngIf="submitted && f.firstname.errors" class="invalid-feedback">
                                              <div *ngIf="f.firstname.errors.required">FirstName is required</div>
                                        </div>
                                     </div>
                               </div> 
                               <div class="col-sm-6">
                                  <div class="form-group">
                                     <label>Email</label>
                                     <input type="text" formControlName="email" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.email.errors }" />
                                     <div *ngIf="submitted && f.email.errors" class="invalid-feedback">
                                        <div *ngIf="f.email.errors.required">Email is required</div>
                                        <div *ngIf="f.email.errors.email">Email must be a valid email address</div>
                                     </div>
                                  </div>
                               </div>
                               <div class="col-sm-6">
                                     <div class="form-group">
                                        <label>Mobile</label>
                                        <input type="text" formControlName="mobile" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.mobile.errors }" />
                                        <div *ngIf="submitted && f.mobile.errors" class="invalid-feedback">
                                           <div *ngIf="f.mobile.errors">Mobile must be Valid and at least 10 digits</div>
                                          
                                        </div>
                                     </div>
                                  </div>
                               <div class="col-sm-6">
                                  <div class="form-group">
                                     <label>Password</label>
                                     <input type="password" formControlName="password" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.password.errors }" />
                                     <div *ngIf="submitted && f.password.errors" class="invalid-feedback">
                                        <div *ngIf="f.password.errors.required">Password is required</div>
                                        <div *ngIf="f.password.errors.minlength">Password must be at least 6 characters</div>
                                     </div>
                                  </div>
                               </div>
                   </div>
                   <button type="submit" class="btn btn-primary">Submit</button>
                      </form>
    </div>

     

    7. Now you need to add below code into your mypage.php file to connect php mysql and save data in database:

    In phpmyadmin, I have created database user and in user database, I have created userdata table, in other words, this code will save data in phpmyadmin. For this, you need xampp software to run php and mysql.

    <?php
    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Methods: PUT, GET, POST");
    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
    $conn = new mysqli('localhost','root','','user');
    $sql = "INSERT INTO userdata (firstname, password, email, mobile) VALUES ('".$_POST['firstname']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['mobile']."')";
    
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    
    $conn->close();

     

    php mysql
    phpmyadmin

    8. Fill the form to save data:

    9. Data saved  successfully:

    However, In this post, we have successfully added data in php mysql and if you have any kind of query then please me know. In next post, I will tell you, how to get the from php mysql in angular and update it, so please be in touch.

    Jassa

    Thank you

  • Angular 8 with php tutorial

    Angular 8 with php tutorial

    Hello to all, welcome to therichpost.com. Today I am starting, Angular 8 with php tutorial and this is the part 1. In this, I will tell you, bootstrap form integration in Angular 8 with proper validations.

    Angular 8 with php tutorial
    Angular 8 with php tutorial

    I will tell you, all the steps to install and setup angular 8 and bootstrap 4 on your local machine. This is the first part of my Angular 8 with php tutorial. In other words this will be the complete angular php tutorial.

    In this, however we will make form in bootstrap 4 and apply validations with angular 8 .

    Angular 8 form validation
    Angular 8 form validation

    Here are the steps and please follow carefully:

    1. Here are the basics commands to install angular 8 on your system:

    npm install -g @angular/cli 
    
    ng new angularpopup //Create new Angular Project
    
    $ cd angularpopup // Go inside the Angular Project Folder
    
    ng serve --open // Run and Open the Angular Project
    
    http://localhost:4200/ // Working Angular Project Url

     

    2. After done with above, you need to run below commands to set bootstrap environment into your angular 8 application:

    npm install --save bootstrap

     

    3. Now you need to add below code into your angular.json file:

    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/bootstrap/dist/css/bootstrap.min.css"
              ],
    "scripts": ["node_modules/bootstrap/dist/js/bootstrap.min.js"]
    ...

     

    4. Now you need to add below code into your src/app/app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import { ReactiveFormsModule } from '@angular/forms';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        ReactiveFormsModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

     

    5. Now you need to add below code into your src/app/app.component.ts file:

    import { Component } from '@angular/core';
    import { FormBuilder, FormGroup, Validators } from '@angular/forms';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      registerForm: FormGroup;
      submitted = false;
      constructor(private formBuilder: FormBuilder) { }
      ngOnInit() {
        this.registerForm = this.formBuilder.group({
            email: ['', [Validators.required, Validators.email]],
            password: ['', [Validators.required, Validators.minLength(6)]],
            firstname: ['', [Validators.required, Validators.minLength(6)]],
            mobile: ['', [Validators.required, Validators.pattern(/^-?(0|[1-9]\d*)?$/), Validators.minLength(10)]]
        });
    }
    // convenience getter for easy access to form fields
    get f() { return this.registerForm.controls; }
    onSubmit() {
        this.submitted = true;
        // stop here if form is invalid
        if (this.registerForm.invalid) {
            return;
        }
    }
    }

     

    6. Now you need to add below code into src/app/app.component.html file:

    <div class="container">
          <h1 class="text-center">Angular 8 with php tutorial part 1</h1>
        <form [formGroup]="registerForm" (ngSubmit)="onSubmit()">
                            <div class="row">
                               <div class="col-sm-6">
                                  <div class="form-group">
                                        <label>FirstName</label>
                                        <input type="text" formControlName="firstname" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.firstname.errors }" />
                                        <div *ngIf="submitted && f.firstname.errors" class="invalid-feedback">
                                              <div *ngIf="f.firstname.errors.required">FirstName is required</div>
                                        </div>
                                     </div>
                               </div> 
                               <div class="col-sm-6">
                                  <div class="form-group">
                                     <label>Email</label>
                                     <input type="text" formControlName="email" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.email.errors }" />
                                     <div *ngIf="submitted && f.email.errors" class="invalid-feedback">
                                        <div *ngIf="f.email.errors.required">Email is required</div>
                                        <div *ngIf="f.email.errors.email">Email must be a valid email address</div>
                                     </div>
                                  </div>
                               </div>
                               <div class="col-sm-6">
                                     <div class="form-group">
                                        <label>Mobile</label>
                                        <input type="text" formControlName="mobile" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.mobile.errors }" />
                                        <div *ngIf="submitted && f.mobile.errors" class="invalid-feedback">
                                           <div *ngIf="f.mobile.errors">Mobile must be Valid and at least 10 digits</div>
                                          
                                        </div>
                                     </div>
                                  </div>
                               <div class="col-sm-6">
                                  <div class="form-group">
                                     <label>Password</label>
                                     <input type="password" formControlName="password" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.password.errors }" />
                                     <div *ngIf="submitted && f.password.errors" class="invalid-feedback">
                                        <div *ngIf="f.password.errors.required">Password is required</div>
                                        <div *ngIf="f.password.errors.minlength">Password must be at least 6 characters</div>
                                     </div>
                                  </div>
                               </div>
                   </div>
                   <button type="submit" class="btn btn-primary">Submit</button>
                      </form>
    </div>

     

    After that, In my next post or I can say, in second part of this tutorial, I will tell you, how we can save angular 8 form data in php mysql database. If you have any suggestions then please write in comments below.

    In the end, don’t forgot to run ng serve command. If you have any query then do comment below.

    Jassa

    Thank you.