Author: therichpost

  • Angular 8 custom nested menu working example

    Angular 8 custom nested menu working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 8 custom nested menu working example.

    Angular 8 custom nested menu working example
    Angular 8 custom nested menu working example

    I have done with custom code and I am showing limited menus and if you want more then you can add according to your requirement.

    For styling, I used bootstrap and font awesome cdns.

    Here I am sharing the code and you need to add carefully:

    1. This below code, you need to add into your app.component.ts file:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <aside class="left-sidebar">
      <div class="scroll-sidebar">
         <nav class="sidebar-nav">
            <ul id="sidebarnav">
    
               <li [ngClass]="{'active': menus[2]}">
                  <a (click)="navmenuclick(2)" class="has-arrow" [attr.aria-expanded]="true ? menus[2]:true"><i class="fa fa-users m-r-5" aria-hidden="true"></i><span class="hide-menu">Customers</span></a>
                  <ul *ngIf=menus[2] class="collapse in">
                     <li><a [ngClass]="{'active': submenu['2.0']}" ><i class="fa fa-caret-right m-r-5"></i>Manage Customers</a></li>
                     <li><a [ngClass]="{'active': submenu['2.1']}" ><i class="fa fa-caret-right m-r-5"></i>Add Customer</a></li>
                  </ul>
               </li>
    
    
               <li [ngClass]="{'active': menus[3]}">
                  <a (click)="navmenuclick(3)" class="has-arrow" [attr.aria-expanded]="true ? menus[3]:true"><i class="fa fa-user-plus m-r-5" aria-hidden="true"></i><span class="hide-menu">Staff</span></a>
                  <ul *ngIf=menus[3] class="collapse in">
                     <li><a [ngClass]="{'active': submenu['3.0']}" ><i class="fa fa-caret-right m-r-5"></i>Manage Staff</a></li>
                     <li><a [ngClass]="{'active': submenu['3.1']}" ><i class="fa fa-caret-right m-r-5"></i>Add Staff</a></li>
                  </ul>
               </li>
    
    
               <li [ngClass]="{'active': menus[4]}">
                  <a (click)="navmenuclick(4)" class="has-arrow" [attr.aria-expanded]="true ? menus[4]:true"><i class="fa fa-files-o m-r-5" aria-hidden="true"></i><span class="hide-menu">Pages</span></a>
                  <ul *ngIf=menus[4] class="collapse in" aria-expanded="false">
                     <li><a [ngClass]="{'active': submenu['4.0']}" ><i class="fa fa-caret-right m-r-5"></i>All Pages</a></li>
                     <li><a [ngClass]="{'active': submenu['4.1']}" ><i class="fa fa-caret-right m-r-5"></i>Add New Page</a></li>
                  </ul>
               </li>
            </ul>
         </nav>
      </div>
    </aside>

     

    2. Now you need to add below code into your app.component.ts file:

    import { Component } from '@angular/core';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'childmenu';
      public menus = new Array();
      public submenu = new Array();
      navmenuclick(value){
        for(let i= 0; i<5; i++){
          if(i != value){
              this.menus[i] = false;	
              /*Submenu Code Start*/
              this.submenu[i+'.'+0] = false;
              this.submenu[i+'.'+1] = false;
              /*Submenu Code Close*/
          }
        }
    
        if(this.menus[value] == true){
          this.menus[value] = false;  
        }else{
          this.menus[value] = true;  
        }
     }
    }

     

    This is it and if you have any query then please comment below.

    jassa

    Thank you

  • How to add download pdf link in woocommerce single product page?

    How to add download pdf link in woocommerce single product page?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to add download pdf link in woocommerce single product page?

    I am showing download pdf link on single product page with help of woocommerce hook.

    Here is the woocommerce hook and please add carefully into your theme’s functions.php file:

    add_action('woocommerce_before_single_product_summary','download_pdf',11);
    function download_pdf()
    {
        echo "<a href='add_your_pdf_link' target='_blank'>Download PDF</a>"; 
    }

     

    If you have any query regarding this then please do comment below.

    Jassa

    Thank you

  • How to implement wow js in angular 8?

    How to implement wow js in angular 8?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to implement wow js in angular 8?

    This is very interesting topic and wow js is very interesting and very popular nowadays.

    Guys here is the link with posts for Angular 16+ : Angular 16 + Tutorial Posts

    Here is the the implementation 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 angularwow //Create new Angular Project
    
    cd angularwow // 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 wow js environment into your angular 8 application:

    npm install --save wowjs
    
    npm install --save ngx-wow
    
    npm install jquery --save
    
     npm install bootstrap --save
    
    

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

    "styles": [
                  ...
                  "node_modules/bootstrap/dist/css/bootstrap.min.css",
                  "node_modules/wowjs/css/libs/animate.css"
                ],
                "scripts": [
                  "node_modules/jquery/dist/jquery.js",
                  "node_modules/bootstrap/dist/js/bootstrap.js",
                  "node_modules/wowjs/dist/wow.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 { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { AppComponent } from './app.component';
    import { NgwWowModule } from 'ngx-wow';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule,
        NgwWowModule
      ],
      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 { NgwWowService } from 'ngx-wow';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      constructor(private wowService: NgwWowService) {
        this.wowService.init();
      }
    }

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

    <div class="jumbotron text-center">
      <h1>WOWJS</h1>
      <p>Angular 8</p> 
    </div>
    <div class="container">
      <div class="row text-center" style="display: block;">
           <img class="wow fadeInDown" data-wow-delay="0.5s" src="https://wowjs.uk/img/wow-logo.jpg">		
      </div>
    </div>

    6. Please below command into your terminal to taste the output:

    ng serve

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

    Jassa

    Thank you

  • How to implement toastr notifications in angular 8?

    How to implement toastr notifications in angular 8?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to implement toastr notifications in angular 8?

    I am showing toastr notifications in Angular 8 button click event. We can use this in many ways. Here is the working picture of Toastr Notifications in Angular 8 Application:

    toastr notifications in angular 8
    toastr notifications in angular 8

    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 angulartoastr //Create new Angular Project
    
    $ cd angulartoastr // 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 toastr environment into your angular 8 application:

    npm install ngx-toastr --save
    
    npm install @angular/animations --save

     

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

    ...
    "styles": [
                  ...
                  "node_modules/ngx-toastr/toastr.css"
                  ...
                ]
    ...

     

    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 { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { ToastrModule } from 'ngx-toastr';
    import { AppComponent } from './app.component';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule, // required animations module
        ToastrModule.forRoot() // ToastrModule added
      ],
      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 { ToastrService } from 'ngx-toastr';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angulartoastr';
      constructor(private toastr: ToastrService) {}
      showSuccess() {
        this.toastr.success('Hello world!', 'Toastr fun!',
        {timeOut: 2000});;
      }
      showError() {
      this.toastr.error('everything is broken', 'Major Error', {
      timeOut: 3000
    });
    }
    }

     

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

    <div style="text-align:center">
      <h1>
        Angular Toastr:
      </h1>
    </div>
    <button (click) = "showSuccess()">Oprn Angular Toastr Success</button>
    <br/><br/>
    <button (click) = "showError()">Oprn Angular Toastr Error</button>

     

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

    Jassa

    Thank you

  • How to integrate owl carousel in reactjs latest versions?

    How to integrate owl carousel in reactjs latest versions?

    Hello to all, welcome to therichpost.com. Today In this post, I will tell you, How to integrate owl carousel in reactjs latest versions?

    Very first, you need to setup reactjs on your machine so for that please check below working link:
    install-reactjs

    1. After setup Reactjs on your system run below command to install owl carousel on your reactjs application:

    npm install --save react-owl-carousel

     

    2. Now add below code  into your src/index.js file:

    import React from 'react';
    import ReactDOM from 'react-dom';
    import OwlCarousel from 'react-owl-carousel';
    import 'owl.carousel/dist/assets/owl.carousel.css';
    import 'owl.carousel/dist/assets/owl.theme.default.css';
    const options = {
        items: 4,
    };
    class Hello extends React.Component{
      render()
      {
        return (
        <OwlCarousel
        className="owl-theme"
        loop
        margin={10}
        nav
    >
         
    <div class="item">
    <img alt="img1" src="https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/model/aventador/aventador-svj-roadster/car/SVJ_Roadster_gateway%20modelli.png"/></div>
    <div class="item">
    <img alt="img1" src="https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/model/aventador/aventador-svj-roadster/car/SVJ_Roadster_gateway%20modelli.png"/></div>
    <div class="item">
    <img alt="img1" src="https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/model/aventador/aventador-svj-roadster/car/SVJ_Roadster_gateway%20modelli.png"/></div>
    <div class="item">
    <img alt="img1" src="https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/model/aventador/aventador-svj-roadster/car/SVJ_Roadster_gateway%20modelli.png"/></div>
    <div class="item">
    <img alt="img1" src="https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/model/aventador/aventador-svj-roadster/car/SVJ_Roadster_gateway%20modelli.png"/></div>
    <div class="item">
    <img alt="img1" src="https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/model/aventador/aventador-svj-roadster/car/SVJ_Roadster_gateway%20modelli.png"/></div>
    
    </OwlCarousel>
        )
      }
    }
    
    ReactDOM.render(<Hello />, document.getElementById('root'));

     

    3. Now add below code into public/index.html file:

    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

     

    This is it and if you have any query then please comment below.

    Jassa

    Thank you.

  • Angular 8 reactive form validation working example

    Angular 8 reactive form validation working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 8 reactive form validation working example.

    If you are new in angular then you can check my old posts related to Angular 8.

    Angular 8 reactive form validation working example
    Angular 8 reactive form validation working example

    Here is the working and testing example for Angular 8 reactive form validation and also for form styling, I have used bootstrap 4 cdn.

    1. Let’s start with some basics commands you need to run into your terminal for angular setup and angular files and folder:

    $ npm install -g @angular/cli //Setup Angular8 atmosphere
    
    $ ng new angularlatest8 //Install New Angular App
    
    /**You need to update your Nodejs also for this verison**/
    
    $ cd angularlatest8 //Go inside the Angular 8 Project

    2. 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 { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { ReactiveFormsModule } from '@angular/forms';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule,
        ReactiveFormsModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    3. Now you need to add below code into scr/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 {
      title = 'my-angular-app';
      registerForm: FormGroup;
      submitted = false;
    
        constructor(private formBuilder: FormBuilder) { }
    
        ngOnInit() {
            this.registerForm = this.formBuilder.group({
                firstName: ['', Validators.required],
                lastName: ['', Validators.required],
                email: ['', [Validators.required, Validators.email]],
                password: ['', [Validators.required, Validators.minLength(6)]]
            });
        }
    
        // 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;
            }
        }
      
    }

    4. Now finally add below code into your src/app/app.component.html file to view final output:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <div class="jumbotron">
        <div class="container">
            <div class="row">
                <div class="col-md-6 offset-md-3">
                    <h3> Welcome to {{ title }}!</h3>
                    <form [formGroup]="registerForm" (ngSubmit)="onSubmit()">
                        <div class="form-group">
                            <label>First Name</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">First Name is required</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>Last Name</label>
                            <input type="text" formControlName="lastName" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.lastName.errors }" />
                            <div *ngIf="submitted && f.lastName.errors" class="invalid-feedback">
                                <div *ngIf="f.lastName.errors.required">Last Name is required</div>
                            </div>
                        </div>
                        <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 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 class="form-group">
                            <button class="btn btn-primary">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    5. Now in the end, don’t forgot to run below command to run angular:

    ng serve

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

    Jassa

    Thank you

  • How to implement Business Hours Fullcalendar  in Angular 8?

    How to implement Business Hours Fullcalendar in Angular 8?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to implement Business Hours Fullcalendar in Angular 8?

    How to implement Business Hours Fullcalendar  in Angular 8?

    In this post, I will implement Business Hours Fullcalendar in Angular 8 with the help of jQuery.

    1. Let start, here are the basics commands to set Angular 8 into your pc:

    $ npm install -g @angular/cli //Setup Angular8 atmosphere
    
    $ ng new angularlatest8 //Install New Angular App
    
    /**You need to update your Nodejs also for this verison**/
    
    $ cd angularlatest8 //Go inside the Angular 8 Project

    2. After Install Angular 8 fresh setup and go inside the Angular 8 setup, run below command into your terminal to install Fullcalendar and jQuery modules:

    $ npm install jquery –save //Add jquery module
    
    $ npm i fullcalendar //Add fullcalendar module
    
    $ npm i moment //Add momentjs library
    
    $ ng serve //Run your Angular 8 Project

     Now you are few inches left to implement Fullcalendar in Angular8

    3. Here is the code, you need to add into your angular.json file in root folder:

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

    4. Here is the code, you need to add 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,
                            defaultView: 'agendaWeek',
                            businessHours: [{
                              dow: [0, 1, 2, 3, 4, 5, 6],
                              start: '09:00',
                              end: '11:00'
                          }, {
                              dow: [0, 1, 2, 3, 4, 5, 6],
                              start: '13:00',
                              end: '18:00'
                          }]
                        });
    
         }, 100);
       }
    }

     

    5. Finally, here is the code for you src/app/app.component.html file:

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

    You are done and if you have any query related to this post, then please do comment below or ask questions.

    Jassa

    Thank you

  • How to add custom field in woocommerce checkout form and validate it?

    How to add custom field in woocommerce checkout form and validate it?

    Hello to all and welcome on therichpost.com. In this post, I will tell you, How to add custom field in woocommerce checkout form and validate it?

    Woocommerce is the best ecommerce platform and famous wordpress plugin.

    I just added select options custom fields with select2 functionality.

    Here is the working hook and you just need to add this into your theme’s functions.php file:

    /////#Add New Field#/////
    add_action( 'woocommerce_after_checkout_billing_form', 'add_extra_fields_after_billing_address',1,1)
    function add_extra_fields_after_billing_address() {
      _e( "Referral:", "add_extra_fields");
      ?>
      <br>
      <select name="add_referral" class="add_referral">
          <option value="">Select Referral</option>
        <option value="Google">Google</option>
        <option value="Facebook">Facebook</option>
        <option value="Other company">Other company</option>
      </select>
    
      <script>
        jQuery(document).ready(function($){
          $(document).ready(function() {
            $('.add_referral').select2();
          });
        })
      </script>
      <?php 
    }
    
    /////#Add New Field Validation#/////
    add_action('woocommerce_after_checkout_validation', 'add_validate',10,2);
    function add_validate($data,$errors) { 
      if ( isset( $_POST['add_referral'])  && empty( $_POST['add_referral'])){
    
        $errors->add( 'validation', __( "<strong>Referral</strong> is a required field." ));
      }
    }

     

    If you have any related to this post or any other query related to woocommerce then feel free to ask.

    Jassa

    Thank you

  • Angular 8 open Bootstrap 4 modal popup with dynamic data on click on Bootstrap 4 table row

    Angular 8 open Bootstrap 4 modal popup with dynamic data on click on Bootstrap 4 table row

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 8 open Bootstrap 4 modal popup with dynamic data on click on Bootstrap 4 table row.

    If you are new in Angular 8 then you can check my old Angular 8 posts.

    Now I will come to the main point and here is the code snippet for Angular 8 open Bootstrap 4 modal popup with dynamic data on click on Bootstrap 4 table row:


    1. Very first, you need to add Bootstrap into your Angular Application so please follow the below link:

    https://therichpost.com/add-bootstrap-to-angular-7

     

    2. Now add below code into your 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 {
      showModal : boolean;
      UserId    : string;
      Firstname : string;
      Lastname  : string;
      Email     : string;
      
      onClick(event)
      {
        this.showModal = true; // Show-Hide Modal Check
          this.UserId = event.target.id;
          this.Firstname = document.getElementById("firstname"+this.UserId).innerHTML;
          this.Lastname = document.getElementById("lastname"+this.UserId).innerHTML;
          this.Email = document.getElementById("email"+this.UserId).innerHTML;
    
      }
      //Bootstrap Modal Close event
      hide()
      {
        this.showModal = false;
      }
    }
    
    
    ---app.component.ts---
    
    import { Component, OnInit } from '@angular/core';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      showModal : boolean;
      UserId    : string;
      Firstname : string;
      Lastname  : string;
      Email     : string;
      
      onClick(event)
      {
        this.showModal = true; // Show-Hide Modal Check
        	this.UserId = event.target.id;
        	this.Firstname = document.getElementById("firstname"+this.UserId).innerHTML;
        	this.Lastname = document.getElementById("lastname"+this.UserId).innerHTML;
        	this.Email = document.getElementById("email"+this.UserId).innerHTML;
    
      }
      //Bootstrap Modal Close event
      hide()
      {
        this.showModal = false;
      }
    }

     

    3. Now add below code into your app.component.html file:

    <div class="container">
      <h2>Basic Table</h2>
      <p>Angular 8 open bootstrap 4 modal popup with dynamic data on click on bootstrap table row</p>            
      <table class="table table-hover">
        <thead>
          <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Email</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <tr class="table-primary">
            <td id="firstname1">John</td>
            <td id="lastname1">Doe</td>
            <td id="email1">john@example.com</td>
            <td id="1" (click)="onClick($event)" style="cursor: pointer;font-weight: bold;">Show</td>
    
          </tr>
          <tr class="table-success">
            <td id="firstname2">Mary</td>
            <td id="lastname2">Moe</td>
            <td id="email2">mary@example.com</td>
            <td id="2" (click)="onClick($event)" style="cursor: pointer;font-weight: bold;">Show</td>
          </tr>
          <tr class="table-danger">
            <td id="firstname3">July</td>
            <td id="lastname3">Dooley</td>
            <td id="email3">july@example.com</td>
            <td id="3" (click)="onClick($event)" style="cursor: pointer;font-weight: bold;">Show</td>
          </tr>
        </tbody>
      </table>
    
      <!-- The Modal -->
      <div class="modal" id="myModal" [style.display]="showModal ? 'block' : 'none'">
        <div class="modal-dialog">
          <div class="modal-content">
          
            <!-- Modal Header -->
            <div class="modal-header">
              <h4 class="modal-title">User Details:</h4>
              <button type="button" class="close" data-dismiss="modal" (click) = "hide()">&times;</button>
            </div>
            
            <!-- Modal body -->
            <div class="modal-body">
             <p>User Id : {{UserId}}</p>
             <p>Firstname : {{Firstname}}</p>
             <p>Lastname : {{Lastname}}</p>
             <p>Email : {{Email}}</p>
            </div>
            
            <!-- Modal footer -->
            <div class="modal-footer">
              <button type="button" class="btn btn-danger" data-dismiss="modal" (click) = "hide()">Close</button>
            </div>
            
          </div>
        </div>
      </div>
    </div>

     

    If you have any query related to this post, then do comment below or ask question.

    Harjas,

    Thank you

  • Angular 8 with laravel 6 php mysql data

    Angular 8 with laravel 6 php mysql data

    Hello to all, welcome to therichpost.com. In this post, I will tell you, angular 8 with laravel 6 php mysql data.

    If you are new in Angular 8 or Laravel 6 then you can check my old posts.

    Angular 8 with laravel 6 php mysql data
    Angular 8 with laravel 6 php mysql data

    Here is the complete working code and please use this carefully:

    1. Let start, here are the basics commands to set Angular 8 into your pc:

    $ npm install -g @angular/cli //Setup Angular8 atmosphere
    
    $ ng new angular8phpmyadmindatabse//Install New Angular App
    
    /**You need to update your Nodejs also for this verison**/
    
    $ cd angular8phpmyadmindatabse//Go inside the Angular 8 Project

     

    2. After all above setup, here is code, you need to add into your 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. Here is the code, you need to add app.component.ts file:

    This is laravel project path(http://localhost/laravel57/public/api/sample-restful-apis)where I have set the api from where I am getting the data.

    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 {
      title = 'angular8restapi';
      data = [];
      constructor(private http: HttpClient) {
        this.http.get('http://localhost/laravel57/public/api/sample-restful-apis').subscribe(data => {
        this.data.push(data);
        console.log(this.data);
        }, error => console.error(error));
      }
    }

     

    4. Here is the code you need to add into app.component.html file:

    <table>
        <tr>
          <th>Name</th>
          <th>Domain</th>
          
        </tr>
        <tr *ngFor="let mydata of data[0]">
          <td>{{mydata.name}}</td>
          <td>{{mydata.domain}}</td>
        </tr>
    </table>

     

    5. Here is the code, you need add into app.component.css file:

    table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;
      }
      
      td, th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;
      }
      
      tr:nth-child(even) {
        background-color: #dddddd;
      }

     

    Laravel Code

    1. Here is the code, you need to into your laravel 6 api.php file, where we will set the route:

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

     

    2. Here is the code, you need to laravel57\app\Http\Controllers\HomeController.php file:

    use DB;
    
    class HomeController extends Controller
    {
    ...
    
    
    public function getData()
        {
             $domains = DB::table('emplyee')
            ->select('*')
            ->get(); // you were missing the get method
            return response()->json($domains);
        }
    
    
    ...
    }

     

    In the end here are some important notes to run this all:

    1. Don’t forget to run ng serve command into your terminal.

    2. Don’t forget to start your xampp.

    3. Don’t forget to add your database details into laravel .env file.

    For more information like database and database connectivity and file structure please check this video related to this post.

    Jassa

    Thank you