Category: Angular 13

Angular 13

  • Angular 13 Digital Pin Input Masking Working Demo

    Angular 13 Digital Pin Input Masking Working Demo

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular 13 Digital Pin Input Masking Working Demo.

    Working Demo

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    Angular 13 Digital Pin Input Masking Working Demo
    Angular 13 Digital Pin Input Masking Working Demo

    Friends here is the code snippet and please use this carefully to avoid mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 13 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends we need to run below command into our project terminal to get angular masking and its related modules:

     npm install --save ngx-mask
    
    ng serve --o

    3. Finally friends we need to add below code into our project/src/app/app.component.html file to get the final output on web browser:

    <input type="text" mask="0000" placeholder="0123" /> -
    <input type="text" mask="0000" placeholder="4567" /> -
    <input type="text" mask="0000" placeholder="8901" /> -
    <input type="text" mask="0000" placeholder="2345" />

    4. Now friends  we need to add below code inside project/src/app/app.module.ts file:

    import { NgxMaskModule, IConfig } from 'ngx-mask'
    
    const maskConfigFunction: () => Partial<IConfig> = () => {
      return {
        validation: false,
      };
    
    ...
    imports: [
        ...
        NgxMaskModule.forRoot(maskConfigFunction),
      ],
    ...

    Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • ANGULAR 13 – ANGULAR MATERIAL JSON SERVER CRUD OPERATIONS – Get Users

    ANGULAR 13 – ANGULAR MATERIAL JSON SERVER CRUD OPERATIONS – Get Users

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, ANGULAR 13 – ANGULAR MATERIAL JSON SERVER CRUD OPERATIONS – Get Users.

    Guys before starting this please must check this tutorial : Crud Project Setup

    Material Angular Data Table

    Angular 13 came and very soon Angular 14 will come and if you are new then you must check below two links:

    1. Angular13 Basic Tutorials
    ANGULAR 13 – ANGULAR MATERIAL JSON SERVER CRUD OPERATIONS - Get Users
    ANGULAR 13 – ANGULAR MATERIAL JSON SERVER CRUD OPERATIONS – Get Users
    Json server user data
    Json server user data

    Friends now I proceed onwards and here is the working code snippet and please use carefully this to avoid the mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 11 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends, here we need to run below commands into our project terminal to install angular material modules into our angular application:

    ng add @angular/material

    3. Now friends we just need to add below code into src/app/app.component.html file to get final out on the web browser:

    <div class="mat-elevation-z8">
        <table mat-table [dataSource]="dataSource">
      
          <!-- id Column -->
          <ng-container matColumnDef="id">
            <th mat-header-cell *matHeaderCellDef> No. </th>
            <td mat-cell *matCellDef="let element"> {{element.id}} </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>
      
          <!-- email Column -->
          <ng-container matColumnDef="email">
            <th mat-header-cell *matHeaderCellDef> Email </th>
            <td mat-cell *matCellDef="let element"> {{element.email}} </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 
                       aria-label="Select page of periodic elements">
        </mat-paginator>
      </div>

    4. Now friends we just need to add below code into src/app/app.module.ts file:

    ...
    import {  MatTableModule } from '@angular/material/table';
    import {  MatPaginatorModule } from '@angular/material/paginator';
    import { HttpClientModule } from '@angular/common/http';
    
    @NgModule({
     ...
      imports: [
       ...
        MatPaginatorModule,
        MatTableModule,
        HttpClientModule
      ],
      ...

    5. Now friends we just need to add below code into src/app/app.component.ts file:

    ...
    import { ViewChild } from '@angular/core';
    import {MatPaginator} from '@angular/material/paginator';
    import {MatTableDataSource} from '@angular/material/table';
    import { HttpClient } from '@angular/common/http';
    export class AppComponent {
      ...
    
      //Material table columns
      displayedColumns: string[] = ['id', 'name', 'email'];
      //Table Data Source
      @ViewChild(MatPaginator) paginator :any = MatPaginator;
    
      //Dynamic Data Variable
      usersData:any;
      constructor(private http: HttpClient){}
    
      @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
    
      ngOnInit() {
           //get request from web api and this web api is totaly free to use
           this.http.get('http://localhost:4000/users').subscribe(data => {
           this.usersData = data;
         
            //Data Table Data Source and pagination with dynamic data
            this.dataSource = new MatTableDataSource(this.usersData);
            this.dataSource.paginator = this.paginator
            
         
              }, error => console.error(error));
       
      
      }
    }
    export interface PeriodicElement {
       name: string;
      position: number;
      email: string;
     
    }

    6. Now guys we need to add below code into project/json-server/db.json file:

    {
        "users": [
          {"id": 1, "name": "Jassa", "email": "therichposts@gmail.com"},
          {"id": 2, "name": "Jassa", "email": "therichposts@gmail.com"},
          {"id": 3, "name": "Jassa", "email": "therichposts@gmail.com"},
          {"id": 4, "name": "Jassa", "email": "therichposts@gmail.com"},
          {"id": 5, "name": "Jassa", "email": "therichposts@gmail.com"},
          {"id": 6, "name": "Jassa", "email": "therichposts@gmail.com"},
          {"id": 7, "name": "Jassa", "email": "therichposts@gmail.com"}
      
        ]
      }

    Friends in the end must run ng serve command into your terminal to run the angular 13 project.

    Now we are done friends. If you have any kind of query, suggestion and new requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.

    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Angular 13 Inactive User State Automatically Logout After 10 Seconds

    Angular 13 Inactive User State Automatically Logout After 10 Seconds

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular 13 Inactive User State Automatically Logout After 10 Seconds.

    Working Demo

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    Angular 13 Inactive User State Automatically Logout After 10 Seconds
    Angular 13 Inactive User State Automatically Logout After 10 Seconds

    Friends here is the code snippet and please use this carefully to avoid mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 13 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends we need to run below command into our project terminal to get angular check user state modules:

    npm install bn-ng-idle
    
    ng serve --o

    3. Now friends  we need to add below code inside project/src/app/app.module.ts file:

    ...
    import { BnNgIdleService } from 'bn-ng-idle'; // import bn-ng-idle service
    
    
    @NgModule({
      ...
      providers: [BnNgIdleService], // add it to the providers of your module
      ...

    4. Now friends  we need to add below code inside project/src/app/app.component.ts file:

    import { Component } from '@angular/core';
    import { BnNgIdleService } from 'bn-ng-idle'; // import it to your component
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
    
      constructor(private bnIdle: BnNgIdleService) {
    
      }
    
      // initiate it in your component OnInit
      ngOnInit(): void {
        //60 = 1 minute
        this.bnIdle.startWatching(60).subscribe((res) => {
          if (res) {
            console.log('session expired');
            // this.router.navigateByUrl('logout');
          }
        });
      }
    }

    Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Angular Material Min Length Validation Working Demo

    Angular Material Min Length Validation Working Demo

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular Material Min Length Validation Working Demo.Guys in this post, I am using below:

    Guys in this post I am using below things:

    1. Angular13
    2. Angular Material
    3. Angular Reactive Forms
    4. FormControls
    5. FormBuilder
    6. Default Angular Validations
    Working Demo

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    Angular Material Min Length Validation Working Demo
    Angular Material Min Length Validation Working Demo

    Friends here is the code snippet and please use this carefully to avoid mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 13 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends we need to run below command into our project terminal to get angular material and its related modules:

    ng add @angular/material
    
    ng serve --o

    3. Finally friends we need to add below code into our project/src/app/app.component.html file to get the final output on web browser:

    <form [formGroup]="myForm" (ngSubmit)="onFormSubmit()">
      <mat-form-field appearance="fill">
          <mat-label>User Name</mat-label>
          <input matInput formControlName="unameFormControl">
          <mat-error *ngIf="myForm.get('unameFormControl').hasError('required')">
              Username is <strong>required</strong>
            </mat-error>
            <mat-error *ngIf="myForm.get('unameFormControl').hasError('minlength')">
              Min lenght <strong>8 char</strong>
            </mat-error>  
        </mat-form-field><br />
        <mat-form-field class="example-full-width" appearance="fill">
          <mat-label>Email</mat-label>
          <input type="email" matInput formControlName="emailFormControl"
                 placeholder="Ex. pat@example.com">
         
          <mat-error *ngIf="myForm.get('emailFormControl').hasError('email')">
            Please enter a valid email address
          </mat-error>
          <mat-error *ngIf="myForm.get('emailFormControl').hasError('required')">
            Email is <strong>required</strong>
          </mat-error>
        </mat-form-field><br />
    
    
        <mat-form-field appearance="fill">
          <mat-label>Password</mat-label>
          <input matInput formControlName="pwdFormControl">
          <mat-error  *ngIf="myForm.get('pwdFormControl').hasError('required')">
            Password is <strong>required</strong>
          </mat-error>
          <mat-error *ngIf="myForm.get('pwdFormControl').hasError('minlength')">
            Min lenght <strong>8 char</strong>
          </mat-error>      
        </mat-form-field><br /><br />
      
        <div mat-dialog-actions>
          <button type="submit" mat-raised-button color="primary">Submit</button>
        </div>
      </form>

    4. Now friends  we need to add below code inside project/src/app/app.module.ts file:

    import {MatInputModule} from '@angular/material/input';
    import { FormsModule, ReactiveFormsModule } from '@angular/forms';
    import {MatIconModule} from '@angular/material/icon';
    import {MatButtonModule} from '@angular/material/button';
    import {MatFormFieldModule} from '@angular/material/form-field';
    ..
    
    imports: [
      
        MatFormFieldModule,
        MatInputModule,
        FormsModule,
        MatIconModule,
        ReactiveFormsModule,
        MatButtonModule
      ],
    ...

    6. Now friends  we need to add below code inside project/src/app/app.component.ts file:

    ...
    import { FormControl, Validators, FormBuilder } from '@angular/forms';
    
    
    /**
     * @title Autocomplete overview
     */
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    
    export class AppComponent {
      ...
      constructor(public fb: FormBuilder) {}
      myForm:any = FormControl;
      onFormSubmit() {
        if (this.myForm.valid) {
          console.log(this.myForm.value);
        } else {
          return;
        }
      }
      ngOnInit(): void {
        this.myForm = this.fb.group({
          unameFormControl: ['', [Validators.required, Validators.minLength(8)]],
          emailFormControl: ['', [Validators.required, Validators.email]],
          pwdFormControl: ['', [Validators.required, Validators.minLength(8)]]
        });
      }
    
    
      
    }
    
    ...

    Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Angular 13 Angular Material Datatable integration

    Angular 13 Angular Material Datatable integration

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular 13 Angular Material Datatable integration.

    Working Demo

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    Angular 13 Angular Material Datatable integration
    Angular 13 Angular Material Datatable integration

    Friends here is the code snippet and please use this carefully to avoid mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 13 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends we need to run below command into our project terminal to get angular material and its related modules:

    ng add @angular/material
    
    ng serve --o

    3. Finally friends we need to add below code into our project/src/app/app.component.html file to get the final output on web browser:

    <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 
                       aria-label="Select page of periodic elements">
        </mat-paginator>
      </div>

    4. Now friends we need to add below code inside project/src/app/app.component.css file:

    table {
      width: 100%;
    }

    5. Now friends  we need to add below code inside project/src/app/app.module.ts file:

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

    6. Now friends  we need to add below code inside project/src/app/app.component.ts file:

    import {AfterViewInit, Component, ViewChild} from '@angular/core';
    import {MatPaginator} from '@angular/material/paginator';
    import {MatTableDataSource} from '@angular/material/table';
    
    /**
     * @title Autocomplete overview
     */
    @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) paginator :any = MatPaginator;
      
    
      ngAfterViewInit() {
        this.dataSource.paginator = this.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'},
    ];

    Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Solved – Angular Material Property ‘paginator’ has no initializer and is not definitely assigned in the constructor

    Solved – Angular Material Property ‘paginator’ has no initializer and is not definitely assigned in the constructor

    Hello guys how are you? Welcome back to my blog therichpost.com. Today in this blog post, I am going to tell you how to Solved – Angular Material Property ‘paginator’ has no initializer and is not definitely assigned in the constructor issue?

    Property 'paginator' has no initializer and is not definitely assigned in the constructor
    Property ‘paginator’ has no initializer and is not definitely assigned in the constructor

    Guys I got this error during code implementing Material Datatable into my Angular 13 Application and using below code snippet and add that inside our component.ts file and we can solved that issue.

    @ViewChild(MatPaginator) paginator :any = MatPaginator;

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Angular 13 – Angular Material Json Server Project Setup For Crud Operations

    Angular 13 – Angular Material Json Server Project Setup For Crud Operations

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular 13 – Angular Material Json Server Project Setup For Crud Operations.

    Working Demo

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    Angular Material Json Server Project Folder Structure
    Angular Material Json Server Project Folder Structure

    Friends here is the code snippet for Angular 13 – Angular Material Json Server Project Setup For Crud Operations and please use this carefully to avoid mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 13 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends we need to run below command into our project terminal to get angular material and its related modules:

    ng add @angular/material
    
    ng serve --o

    3. Finally friends we need to add below code into our project/src/app/app.component.html file to get the final output on web browser:

    <div class="flex-row-container">
      <div class="flex-row-item">1</div>
      <div class="flex-row-item">2</div>
      <div class="flex-row-item">3</div>
      <div class="flex-row-item">4</div>
      <div class="flex-row-item">5</div>
      <div class="flex-row-item">6</div>
    </div>

    4. Now friends in last we need to add below code inside project/src/app/app.component.css file:

    .flex-row-container {
      
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: center;
      padding: 5px;
    }
    .flex-row-container > .flex-row-item {
      flex: 1 1 30%; /*grow | shrink | basis */
      height: 100px;
    }
    
    .flex-row-item {
    background-color: #fff4e6;
    border: 1px solid #f76707;
    text-align: center;
    }    
    @media  screen and (max-width:481px) {
      .flex-row-container > .flex-row-item {
        flex: 100%
      }
    }

    5. Now friends we need to set up json server so very first create empty folder `json-server` inside angular project root and then create `db.json` file and add below code inside it:

    {
        "posts": [
          { "id": 1, "title": "json-server", "author": "typicode" }
        ],
        "comments": [
          { "id": 1, "body": "some comment", "postId": 1 }
        ],
        "profile": { "name": "typicode" }
      }

    6. Now friends open `json-server` folder and run below commands to install and run json server:

    npm install -g json-server
    
    npx json-server --port 4000 --watch db.json 

    Guys we have now all the basics requirements for this crud project. In next post we will start Angular Material Json Server Crud Tutorial Part 1.

    Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Solved – Angular Error Prefer Default Export import/prefer-default-export

    Solved – Angular Error Prefer Default Export import/prefer-default-export

    Hello guys how are you? Welcome back to my blog therichpost.com. Today in this blog post, I am going to tell you how to Solved – Angular Error Prefer Default Export import/prefer-default-export issue?

    Guys I got this error during code committing time via git and then I ran below command and error solved and here is that command:

    git commit -m “message” – -no-verify

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Angular Material Autocomplete showing with image and text

    Angular Material Autocomplete showing with image and text

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular Material Autocomplete showing with image and text.

    Working Demo

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    Angular Material Autocomplete showing with image and text
    Angular Material Autocomplete showing with image and text

    Friends here is the code snippet and please use this carefully to avoid mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 13 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends we need to run below command into our project terminal to get angular material and its related modules:

    ng add @angular/material
    
    ng serve --o

    3. Finally friends we need to add below code into our project/src/app/app.component.html file to get the final output on web browser:

    <form class="example-form">
      <mat-form-field class="example-full-width" appearance="fill">
        <mat-label>State</mat-label>
        <input matInput
               aria-label="State"
               [matAutocomplete]="auto"
               [formControl]="stateCtrl">
        <mat-autocomplete #auto="matAutocomplete">
          <mat-option *ngFor="let state of filteredStates | async" [value]="state.name">
            <img class="example-option-img" aria-hidden [src]="state.flag" height="25">
            <span>{{state.name}}</span> |
            <small>Population: {{state.population}}</small>
          </mat-option>
        </mat-autocomplete>
      </mat-form-field>
    </form>

    4. Now friends we need to add below code inside project/src/app/app.component.css file:

    .mat-option .mat-option-text img{
        width:40px;
        height:40px;
      }
      .mat-option .mat-option-text span{
        font-size:2em;
        padding:0 0 10px 10px;
        margin:0 0 10px 0 !important;
        white-space:nowrap;
      }
      .mat-option{
          line-height: 0!important;
      }

    5. Now friends we need to add below code inside project/src/app/app.component.ts file:

    import {Component} from '@angular/core';
    import {FormControl} from '@angular/forms';
    import {Observable} from 'rxjs';
    import {map, startWith} from 'rxjs/operators';
    
    export interface State {
      flag: string;
      name: string;
      population: string;
    }
    
    /**
     * @title Autocomplete overview
     */
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      stateCtrl = new FormControl();
      filteredStates: Observable<State[]>;
    
      states: State[] = [
        {
          name: 'Arkansas',
          population: '2.978M',
          // https://commons.wikimedia.org/wiki/File:Flag_of_Arkansas.svg
          flag: 'https://upload.wikimedia.org/wikipedia/commons/9/9d/Flag_of_Arkansas.svg',
        },
        {
          name: 'California',
          population: '39.14M',
          // https://commons.wikimedia.org/wiki/File:Flag_of_California.svg
          flag: 'https://upload.wikimedia.org/wikipedia/commons/0/01/Flag_of_California.svg',
        },
        {
          name: 'Florida',
          population: '20.27M',
          // https://commons.wikimedia.org/wiki/File:Flag_of_Florida.svg
          flag: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Flag_of_Florida.svg',
        },
        {
          name: 'Texas',
          population: '27.47M',
          // https://commons.wikimedia.org/wiki/File:Flag_of_Texas.svg
          flag: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Flag_of_Texas.svg',
        },
      ];
    
      constructor() {
        this.filteredStates = this.stateCtrl.valueChanges.pipe(
          startWith(''),
          map(state => (state ? this._filterStates(state) : this.states.slice())),
        );
      }
    
      private _filterStates(value: string): State[] {
        const filterValue = value.toLowerCase();
    
        return this.states.filter(state => state.name.toLowerCase().includes(filterValue));
      }
    }

    6. Now friends we need to add below code inside project/src/app/app.module.ts file:

    import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    
    
    import {MatInputModule} from '@angular/material/input';
    import { MatAutocompleteModule } from '@angular/material/autocomplete';
    import {FormsModule, ReactiveFormsModule} from '@angular/forms';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        AppRoutingModule,
        BrowserAnimationsModule,
        MatAutocompleteModule,
        FormsModule,
        ReactiveFormsModule,
        MatInputModule
      ],
      schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks

  • Angular Material With Flex Three Columns Layout

    Angular Material With Flex Three Columns Layout

    Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular Material With Flex Three Columns Layout.

    Working Demo

    Angular 13 came and if you are new then you must check below two links:

    1. Angular 13 Demos
    2. AngularMaterial

    Angular Material With Flex Three Columns Layout
    Angular Material With Flex Three Columns Layout
    Angular Material with Flex Responsive Layout Phone

    Friends here is the code snippet and please use this carefully to avoid mistakes:

    1. Firstly friends we need fresh angular 13 setup and for this we need to run below commands but if you already have angular 13 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

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

    2. Now friends we need to run below command into our project terminal to get angular material and its related modules:

    ng add @angular/material
    
    ng serve --o

    3. Finally friends we need to add below code into our project/src/app/app.component.html file to get the final output on web browser:

    <div class="flex-row-container">
      <div class="flex-row-item">1</div>
      <div class="flex-row-item">2</div>
      <div class="flex-row-item">3</div>
      <div class="flex-row-item">4</div>
      <div class="flex-row-item">5</div>
      <div class="flex-row-item">6</div>
    </div>

    4. Now friends in last we need to add below code inside project/src/app/app.component.css file:

    .flex-row-container {
      
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: center;
      padding: 5px;
    }
    .flex-row-container > .flex-row-item {
      flex: 1 1 30%; /*grow | shrink | basis */
      height: 100px;
    }
    
    .flex-row-item {
    background-color: #fff4e6;
    border: 1px solid #f76707;
    text-align: center;
    }    
    @media  screen and (max-width:481px) {
      .flex-row-container > .flex-row-item {
        flex: 100%
      }
    }

    Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

    Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
    I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

    Jassa

    Thanks