Author: therichpost

  • Angular 9 Tinymce in Bootstrap Modal Popup working example

    Angular 9 Tinymce in Bootstrap Modal Popup working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 9 Tinymce in Bootstrap Modal Popup working example.

    Angular 9 is getting popularity these days. If you are new in Angular then you can check my old posts related to Angular.

    Today I will implement TinyMCE – JavaScript Library for Rich Text Editing in Angular 9 latest version.


    Angular 9 Tinymce in Bootstrap Modal Popup working example
    Angular 9 Tinymce in Bootstrap Modal Popup working example

    Here is the working code snippet, you need to follow carefully:

    1. Here are some basics commands to add new Angular setup and other libraries:

    ng new angulartinymc
    
    cd angulartinymc
    
    npm i tinymce
    
    npm install --save bootstrap
    

     

    2. Here is code, you need to add your angular.json file:

    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/tinymce/skins/ui/oxide/skin.min.css",
                  "node_modules/tinymce/skins/ui/oxide/content.min.css",
            "node_modules/bootstrap/dist/css/bootstrap.min.css"
    
                ],
    "scripts": [
                  "node_modules/tinymce/tinymce.min.js",
                  "node_modules/tinymce/themes/silver/theme.js",
            "node_modules/bootstrap/dist/js/bootstrap.min.js"
                ]
    ...

     

    3. Here is the code, you need to add app.component.ts file:

    import { Component, OnInit } from '@angular/core';
    
    declare var tinymce: any;
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
     
      showModal: boolean;
      show()
      {
        this.showModal = true; // Show-Hide Modal Check
        
      }
      //Bootstrap Modal Close event
      hide()
      {
        this.showModal = false;
      }
      ngOnInit() {
        
          tinymce.init(
            {
                selector: "#mymce1"
            });
      }
    }
    

     

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

    <div class="container">
    
    <button type="button" class="btn btn-primary" (click) = "show()">Open Pop Up with Tinymce</button>
       
    <!-- Creates the bootstrap modal where the image will appear -->
    <div [style.display]="showModal ? 'block' : 'none'" class="modal" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="myModalLabel">Login</h4>
        </div>
        <div class="modal-body">
            <textarea id="mymce1"></textarea>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-dark" data-dismiss="modal" (click) = "hide()">Close</button>
        
        </div>
      </div>
    </div>
    </div>
    </div>

     

    In the end run ng serve command and check the output. If you have any query related to this post, then please do comment below.

    Jassa,

    Thank you.

  • Angular 9 Toastr Notifications Working Example

    Angular 9 Toastr Notifications Working Example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 9 Toastr Notifications Working Example.

    Toastr Notifications are the well designed  popup message and easy to use and implement. Today I am implementing Toastr Notifications in Angular 9. I am very happy for Angular 9.

    I am showing toastr notifications in Angular 9 button click event. We can use this in many ways.

    Here is the working picture of Toastr Notifications in Angular 9 Application:

    Angular 7 Toastr Notifications Working Example
    success_notification
    error_notification

    Here are the working steps you need to follow:

    1. Here are the few commands to install Angular 9:

    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 commands, you need to below command to install toastr into your application:

    npm install ngx-toastr --save
    npm install @angular/animations --save
    1. After all ablove, you need to add below into src/styles.css:
    // regular style toast 
    @import '~ngx-toastr/toastr.css';

    4. Now, add below code into your 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 add below code into your 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, finally add below code into app.component.html file:

    <!--The content below is only a placeholder and can be replaced.-->
    <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>

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

    Thank you,

    Jass

    TheRichPost

  • Angular 9 Material input fields working example

    Angular 9 Material input fields working example

    Hello to all, welcome on therichpost.com. In this post, I will tell you, Angular 9 Material input fields working example.

    Angular 9 Material input fields working example
    Angular 9 Material input fields working example

    Post Working:

    In this post, I am showing Angular material input fields with proper styling and animation.

    Here is the complete working code snippet and please follow carefully:

    1. Here are some basics commands which will help you to install Angular 9 setup on your machine:

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

     

    2. Now here are the commands to install Angular Material modules on your Angular 9 setup:

    npm install --save @angular/material
    
    npm install --save @angular/cdk

     

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

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { MatFormFieldModule } from '@angular/material/form-field';
    import {MatInputModule} from '@angular/material/input';
    import { AppComponent } from './app.component';
    import {MatSelectModule} from '@angular/material/select';
    import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        MatFormFieldModule,
        MatInputModule,
        MatSelectModule,
        BrowserAnimationsModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

     

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

    "styles": [
                   ...
                  "node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
                   ...
               ],

     

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

    <link href="https://fonts.googleapis.com/icon?family=Material+Icons&display=block" rel="stylesheet">
    <div class="example-container">
      <mat-form-field appearance="fill">
        <mat-label>Input</mat-label>
        <input matInput>
      </mat-form-field>
      <br>
      <mat-form-field appearance="fill">
        <mat-label>Select</mat-label>
        <mat-select>
          <mat-option value="option">Option</mat-option>
        </mat-select>
      </mat-form-field>
      <br>
      <mat-form-field appearance="fill">
        <mat-label>Textarea</mat-label>
        <textarea matInput></textarea>
      </mat-form-field>
      <button mat-button>Click me!</button>
    </div>
    

     

    This is it and don’t forget to run ng serve command and check the output. If you have any kind of query then please do comment below.

    Jassa

    Thank you

  • How to implement Full Calendar in Angular 9?

    How to implement Full Calendar in Angular 9?

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

    FullCalendar has been update to version 5 so please check below link:

    Post Working:

    I am showing javascript fullcalendar in angular9.
    How to implement Full Calendar in Angular 9?
    How to implement Full Calendar in Angular 9?


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

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

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

    2. After Install Angular 9 fresh setup and go inside the Angular 9 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 Angular9

    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,
                            events: [
                                {
                                    title : 'This is your',
                                    start : '2020-03-03T12:30:00',
                                    color : '#f9c66a' // override!
                                },
                                {
                                    title : 'Your meeting with john',
                                    start : '2020-03-07T12:30:00',
                                    end   : '2019-03-09',
                                    color : "#019efb"
                                },
                                {
                                    title  : 'This is Today',
                                    start  : '2020-03-12T12:30:00',
                                    allDay : false, // will make the time show,
                                    color  : "#57cd5f"
                                }
                            ],  // request to load current events
                        });
    
         }, 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

  • Angular 9 Datatables working example

    Angular 9 Datatables working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 9 Datatable Working Example.

    Angular 12 has just launched and it is in very high in demand. Angular 12 increased his performance speed. I am showing the data in Datatables with custom json data and also for giving good look to datatable, I have used bootstrap in it, here is the working picture and don’t forget to install latest node version.

    Angular 9 Datatables Working Example
    Angular 9 Datatables working example

    Here is the complete working code snippet for Angular 9 Datatables working example and use this carefully:

    1. Here are the basics commands, you need to run for latest angular 9 setup and environment:

    $ npm install -g @angular/cli
    
    $ ng new angulardatatables
    
    $ cd angulardatatables
    
    $ ng serve
    
    //Here is the url, you need to run into your browser and see working angular test project
    http://localhost:4200/
    
    

    2. Here are the basics commands, you need to run into your terminal for datatable and its dependencies:

    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

    3. After done with commands add below code into you 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",
                ]
    ...

    4. Now add below code into your app.module.ts file:

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

    5. Now add below code into 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: 'therichpost', email: 'therichpost@gmail.com', website:'therichpost.com'},
        {name: 'therichpost', email: 'therichpost@gmail.com', website:'therichpost.com'},
        {name: 'therichpost', email: 'therichpost@gmail.com', website:'therichpost.com'},
        {name: 'therichpost', email: 'therichpost@gmail.com', website:'therichpost.com'},
    ];
    
      title = 'angulardatatables';
      dtOptions: DataTables.Settings = {};
      ngOnInit() {
        this.dtOptions = {
          pagingType: 'full_numbers',
          pageLength: 5,
          processing: true
        };
    }
    }

    6. Now add below code into 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>

    Don’t forget to run ng serve command to see final output.

    Working Example

    Guys if you have any kind of query then feel free to comment below.

    Jassa Jatt

    Thank you

  • Angular 9 owl carousel with Node Js backend

    Angular 9 owl carousel with Node Js backend

    Hello to all, welcome again on therichpost.com. In this post, I will tell you, Angular 9 owl carousel with Node Js backend.

    Post Working:

    In this post, I am implementing Owl Carousel in Angular 9 and showing images in that slider with Node js backend.

    Here is the working video from where you can get Owl Carousel In Angular 8, 9:

    Here is the working code snippet and please follow carefully:

    1. Very first, here are common basics steps to add angular 9 application on your machine:

    $ npm install -g @angular/cli
    
    $ ng new angularowlslider // Set Angular9 Application on your pc
    
    cd angularowlslider // Go inside project folder
    
    ng serve // Run project
    
    http://localhost:4200/  //Check working Local server

     

    2. Now run below command into your terminal to include owl carousel package into your angular 9 application:

    npm i ngx-owl-carousel-o

     

    3. Now, add below code into your angular.json file:

    ....
    "styles": [
        "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.carousel.min.css",
        "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.theme.default.min.css",
        "src/styles.css"
      ],
    ....

     

    4. Now add below code into your app.module.ts file:

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

     

    5. Now add below code into your app.component.ts file:

    In this, I have also made API call to get data from node jsbackend:

    import { Component } from '@angular/core';
    import { HttpClient} from '@angular/common/http';
    import { OwlOptions } from 'ngx-owl-carousel-o';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      images:any;
      constructor(private http: HttpClient){
        this.http.get('http://localhost/8080/api/data').subscribe(data => {
            this.images = data;
            }, error => console.error(error));
      }
     
      
      customOptions: OwlOptions  = {
        loop: true,
        mouseDrag: false,
        touchDrag: false,
        pullDrag: false,
        dots: false,
        navSpeed: 700,
        navText: ['', ''],
        responsive: {
          0: {
            items: 1
          },
          400: {
            items: 2
          },
          740: {
            items: 3
          },
          940: {
            items: 4
          }
        },
        nav: true
      }
    }

     

    6. Finally add, below code into your app.component.html file:

    In this, I am getting images data with *ngfor looping:

    <div style="text-align:center">
      <h1>
        Welcome to {{ title }}!
      </h1>
      <div>Some tags before</div>
      <owl-carousel-o [options]="customOptions">
        <ng-container *ngFor="let image of this.images;">
          <ng-template carouselSlide><img src="{{image.image}}"></ng-template> 
        </ng-container> 
      </owl-carousel-o>
    
      <div>Some tags after</div>
    </div>

     

    7. Here I have made custom API in nodejs file from where I am showing images in Owl Carousel Angular 9:

    const express = require('express');
    const app = express();
    const cors = require('cors');
    app.use(cors());
    //I create api route with custom data
    app.route('/api/data').get((req, res) => {
    res.send({
    events: [{ image: 'https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg' },{ image: 'https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg' },{ image: 'https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg' } ]
    });
    });
    app.listen(8080, () => {
    console.log('Server started!');
    });

     

    8. After execute node file with node node.js command, you will see below json data into your browser:

    This is it and if you have any query related to this post, then please let me know or comment below.

    Jassa

    Thank you

  • Angular 9 Google Maps working example

    Angular 9 Google Maps working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 9 Google Maps working example.

    angular google maps
    angular google maps

    Post Working:

    I am showing google maps in Angular 9.

    Here is the complete code snippet and please follow carefully:

    1. Very first, here are common basics steps to add angular 9 application on your machine:

    $ npm install -g @angular/cli
    
    $ ng new angulargooglemaps // Set Angular9 Application on your pc
    
    cd angulargooglemaps // Go inside project folder
    
    ng serve // Run project
    
    http://localhost:4200/  //Check working Local server

     

    2. Now run below command into your terminal to include google maps package into your angular 9 application:

    npm install @agm/core --save

     

    3. Now add below code into your app.module.ts file:

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

     

    4. Add, below code into your app.component.ts file:

    import { Component } from '@angular/core';
    import { AgmCoreModule } from '@agm/core';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angulargooglemap';
      lat: number = 43.653908;
      lng: number = -79.384293;
    }

     

    5. Add below code into app.component.html file:

    <agm-map [latitude]="lat" [longitude]="lng">
      <agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
    </agm-map>

     

    5. Finally add below code into app.component.css file:

    agm-map {
        height: 300px;
      }

     

    This is it and if you have any kind of query then please let me know. Don’t forget to run ng serve command.

    Jas

    Thank you

  • Angular 9 image cropper working example

    Angular 9 image cropper working example

    Hello to all, welcome to therichpost.com. In this post, I will show you, Angular 9 image cropper working example.

    Angular 9 image cropper working example
    Angular 9 image cropper working example

    Post Working:

    In this post, I am showing how to crop image in Angular 9.

    Here is the working code snippet and please follow carefully:

    1. Very first, here are common basics steps to add angular 9 application on your machine:

    $ npm install -g @angular/cli
    
    $ ng new angularimage // Set Angular9 Application on your pc
    
    cd angularimage // Go inside project folder
    
    ng serve // Run project
    
    http://localhost:4200/  //Check working Local server

     

    2. Now run below command into your terminal to include image cropper package into your angular 9 application:

    npm install ngx-image-cropper --save

     

    3. Now add below code into your app.module.ts file:

    import { ImageCropperModule } from 'ngx-image-cropper';
    @NgModule({
        imports: [
            ...
            ImageCropperModule
        ],
    

     

    4. Add, below code into your app.component.ts file:

    import { ImageCroppedEvent } from 'ngx-image-cropper';
    
    export class YourComponent {
    
        imageChangedEvent: any = '';
        croppedImage: any = '';
        
        fileChangeEvent(event: any): void {
            this.imageChangedEvent = event;
        }
        imageCropped(event: ImageCroppedEvent) {
            this.croppedImage = event.base64;
        }
        imageLoaded() {
            // show cropper
        }
        cropperReady() {
            // cropper ready
        }
        loadImageFailed() {
            // show message
        }
    }

     

    5. Finally add below code into app.component.html file:

    <image-cropper
        [imageChangedEvent]="imageChangedEvent"
        [maintainAspectRatio]="true"
        [aspectRatio]="4 / 3"
        format="png"
        (imageCropped)="imageCropped($event)"
        (imageLoaded)="imageLoaded()"
        (cropperReady)="cropperReady()"
        (loadImageFailed)="loadImageFailed()"
    ></image-cropper>
    
    <img [src]="croppedImage" />

     

    This is it and if you have any kind of query then please let me know. Don’t forget to run ng serve command.

    Jas

    Thank you

  • Angular 9 with mysql database working example

    Angular 9 with mysql database working example

    Hello to all, welcome to therichpost.com. Today in this blog post, I am going to tell you, Angular 9 with mysql database working example.

    In this post, I am getting the data from pup MySQL database into my angular 9 application and we can use this same code snippet for angular latest versions as well..

    Angular 9 with mysql database working example
    Angular 9 with mysql database working example
    Mysql database working example
    Mysql database working example

    Guy’s Angular 12 came and if you are new or want to learn more about that then please check below links:

    1. Angular 12 Tutorials.

    Here is the complete code snippet and please use carefully:

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

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

     

    2. After come inside angular9phpmyadmindatabse folder, please add below code into angular9phpmyadmindatabse\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 add below code into angular9phpmyadmindatabse\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 {
      title = 'angular9phpmyadmindatabse';
      data = [];
      constructor(private http: HttpClient) {
        this.http.get('http://localhost/employee.php').subscribe(data => {
        this.data.push(data);
        console.log(this.data);
       
        
        }, error => console.error(error));
      }
    }
    

     

    4. Now add below code into angular9phpmyadmindatabse\src\app\app.component.html file:

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

     

    5. Finally for mysql data, please add below code into employee.php file into your htdocs folder and don’t forget to start your XAMPP:

    <?php
    header('Access-Control-Allow-Origin: *');
     $servername = "localhost";
     $username   = "root";
     $password   = "root";
     $dbname     = "employee";
     
     // Create connection
     $conn = new mysqli($servername, $username, $password, $dbname);
     
     // Check connection
     if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
     } 
     
       //echo "Connected successfully";
     $sql = "SELECT * FROM emplyee";
     $result = mysqli_query($conn,$sql); 
     $myArray = array();
     if ($result->num_rows > 0) {
     // output data of each row
         while($row = $result->fetch_assoc()) {
             $myArray[] = $row;
         }
         print json_encode($myArray);
     } 
     else 
     {
         echo "0 results";
     }

     

    Angular MySQL Working

    Guy’s in the end, don’t forget to run ng serve command into your terminal to check the output.

    Guy’s if you have any kind of query related to this post or related to Angular then please contact me or comment below.

    Jassa Jatt

    Angular Expert

    Thank you

  • Angular 8 skeleton loader during API call

    Angular 8 skeleton loader during API call

    Hello to all, welcome again on therichpost.com. In this post, I will tell you, Angular 8 skeleton loader during API call.

    Angular 8 skeleton loader during API call

    Post Working:

    In this post, I am showing skelton loader in Angular 8 during API call.

    Here is the working code snippet and please follow carefully:

    1. Very first, you need to run below commands to install Angular 8 fresh setup:

    $ npm install -g @angular/cli
    
    $ ng new angularloader // Set Angular8 Application on your pc
    
    cd angularloader // Go inside project folder
    
    ng serve // Run project
    
    http://localhost:4200/  //Check working Local server

     

    2. You need to run below command to install Skelton Loader module into your Angular 8 setup:

    npm install ngx-skeleton-loader --save

    3. You need to add below code into your app.module.ts file:

    import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
    import { HttpClientModule } from '@angular/common/http';
    
    
     imports: [
    ...
     HttpClientModule,
     NgxSkeletonLoaderModule
    
    ...
    
     ]

     

    4. Now add below code into your app.component.ts file:

    import { HttpClient} from '@angular/common/http';
    
     export class AppComponent {
    
    skeletonloader = true;
      data: any;
      constructor( private http: HttpClient) {
       
        this.http.get('http:YourAPiURL').subscribe(data => {
            this.data = data;
            this.skeletonloader = false;
            }, error => console.error(error));
       }
    
     }

     

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

     

    <ngx-skeleton-loader count="5" appearance="circle" *ngIf="skeletonloader"> </ngx-skeleton-loader>
        <div *ngIf="!skeletonloader"><h1>Data Loaded</h1></div>
    

     

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

    Jas

    Thank you