Angular HttpClient API Call for Fetching User Data
Program Info
Program Code
×

Angular HttpClient API Call for Fetching User Data

We are fetching user data with the help of angular HttpClient API call.

Footer

×

Angular HttpClient API Call for Fetching User Data

import { CommonModule } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Component, inject } from '@angular/core';

@Component({
  selector: 'app-ng-container',
  imports: [CommonModule],
  templateUrl: './ng-container.component.html',
  styleUrl: './ng-container.component.css'
})
export class NgContainerComponent {

  userList: any [] = [];
  isAPI: boolean = false;

  http = inject(HttpClient);

  getUser(){
    debugger;
    this.isAPI = true;
    this.http.get("https://jsonplaceholder.typicode.com/users").subscribe((result: any)=>{
      debugger;
      this.userList = result;
      this.isAPI = false;

    })
  }


}

Footer

Dynamic Alert Message and User Dropdown Population
Program Info
Program Code
×

Dynamic Alert Message and User Dropdown Population

We displaying dynamic alert message and user dropdown population.

Footer

×

Dynamic Alert Message and User Dropdown Population

<app-alert [alertType]="'warning'" [message]="alertMsg"></app-alert>

<div class="row mt-2">
    <div class="col-6">
        <button class="btn btn-primary" (click)="changeMsg()">Change Alert Message</button><br>

        <button class="btn btn-success mt-2" (click)="getAllUser()">Get Users</button>
    </div>
    <div class="col-6 mt-5">
    <select class="form-select" name="" id="">
        @for(item of userList; track $index)
        {
            <option value="">{{item.name}}</option>
        }
    </select>
</div>
</div>

Footer

Get Users Data from API using HttpClient
Program Info
Program Code
×

Get Users Data from API using HttpClient

We are getting users data from API using HttpClient.

Footer

×

Get Users Data from API using HttpClient

import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { AlertComponent } from '../../../reusable-components/alert/alert.component';
// import { Customer } from '../../../model/class/Cutomer';
import { IUser } from '../../../model/interface/IUser';

@Component({
  selector: 'app-get-api',
  imports: [AlertComponent],
  templateUrl: './get-api.component.html',
  styleUrl: './get-api.component.css'
})
export class GetApiComponent {

  userList: IUser [] = [];
  alertMsg: string = 'welcome to get page';

  changeMsg(){
    this.alertMsg = 'You are most welcome to Get API Page';
  }

  constructor(private http: HttpClient){
    //  this.getAllUser();
  }

  getAllUser(){
    debugger;
    this.http.get("https://jsonplaceholder.typicode.com/users").subscribe((result: any)=>{
      debugger;
      this.userList = result;
    },error=>{
      debugger;
    })
  }

}

Footer

Simple Admin Login Authentication Using Angular
Program Info
Program Code
×

Simple Admin Login Authentication Using Angular

We are creating simple admin login authentication using angular.

Footer

×

Simple Admin Login Authentication Using Angular

import { HttpClient } from '@angular/common/http';
import { Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';

@Component({
  selector: 'app-login',
  imports: [FormsModule],
  templateUrl: './login.component.html',
  styleUrl: './login.component.css'
})
export class LoginComponent {

   userObj: any = {
   userName:'',
   Password:''
  }
  
   onLogin(){
     if(this.userObj.userName == "admin" && this.userObj.Password == "1234567890" ){
        alert("Login Success");
        localStorage.setItem('loginUser',this.userObj.userName);
        this.router.navigateByUrl('emp-list')
     } else{
       alert("Wrong Credential");
     }
   }

}

Footer

User Login Authentication using Angular HttpClient
Program Info
Program Code
×

User Login Authentication using Angular HttpClient

We are creating user login authentication using angular HttpClient.

Footer

×

User Login Authentication using Angular HttpClient

import { HttpClient } from '@angular/common/http';
import { Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';

@Component({
  selector: 'app-login',
  imports: [FormsModule],
  templateUrl: './login.component.html',
  styleUrl: './login.component.css'
})
export class LoginComponent {

  userObj: any = {
    EmailId:'',
    Password:''
  }

  router = inject(Router);
  http = inject(HttpClient);

  onLogin(){
    this.http.post("https://projectapi.gerasim.in/api/UserApp/login", this.userObj).subscribe((res: any)=>{
      if(res.result){
        alert("Login Success");
        localStorage.setItem('loginUser', JSON.stringify(res.data));
        this.router.navigateByUrl('emp-list')
     } else{
       alert(res.message);
     }
    })
    
  }


}

Footer

Dynamic Template Rendering and User List Fetching in Angular
Program Info
Program Code
×

Dynamic Template Rendering and User List Fetching in Angular

We are fetching user list in angular and rendering dynamic template.

Footer

×

Dynamic Template Rendering and User List Fetching in Angular

<div class="mt-2 p-2 bg-secondary text-white rounded">
    <ng-container *ngTemplateOutlet="myTemplate">

    </ng-container>
</div>

<ng-template #myTemplate>
    <h1>ng-container</h1>
</ng-template>

<div class="row pt-3">
    <div class="col-4">
        <button class="btn btn-primary" (click)="getUser()">Laod Users</button>

    </div>
</div>

<div class="row pt-3">
    <div class="col-8">
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>S.No</th>
                    <th>Name</th>
                    <th>User Name</th>
                    <th>Email</th>
                </tr>
            </thead>
            <tbody>
                <ng-container *ngIf="isAPI" class="text-center">
                    <div class="spinner-grow text-muted"></div>
                    <div class="spinner-grow text-primary"></div>
                    <div class="spinner-grow text-success"></div>
                    <div class="spinner-grow text-info"></div>
                    <div class="spinner-grow text-warning"></div>
                    <div class="spinner-grow text-danger"></div>
                    <div class="spinner-grow text-secondary"></div>
                    <div class="spinner-grow text-dark"></div>
                    <div class="spinner-grow text-light"></div>

                </ng-container>

                <ng-container *ngIf="!isAPI">
                    <tr *ngFor="let user of userList;let srNo = index">
                        <td>{{srNo+1}}</td>
                        <td>{{user.name}}</td>
                        <td>{{user.username}}</td>
                        <td>{{user.email}}</td>
    
                    </tr>
                </ng-container>

            </tbody>
        </table>

    </div>
</div>

Footer


×

Name : Krishna Verma    |    Father's Name : Mr. Satish Kumar    |    Email ID : krishnaverma28081997@gmail.com    |    Religion : Hindu    |    Address : Dayampur, kanker khera, Meerut Cantt (250001), UP    |    Date of Birth : 28 August 1997    |    Marital Status : Non-Married    |    Place of Birth : Dayampur Kanker Khera Meerut Cantt.    |    Gender : Male    |    Age : 28    |    Contact : 9520335394    |    Father's Occupation : Sports man    |    Mother's Name : Smt. Kuntesh Devi    |    Mother's Occupation : Homemaker    |    Number of Brothers : 1    |    Number of Sisters : 1    |    Current Residence : Dayampur kanker khera meerut cantt    |    Family Type : Nuclear Family    |    Family Name : verma    |    Height : 5' 6''    |    Weight : 70 kg    |    Complexion : Fair    |    Body Type : Athletic    |    Hair Color : Black    |    Health Status : Good    |    Any Physical Disability : No    |    Highest Qualification : B.Tech (CSE)    |    Master Skill : PHP Laravel    |    Total Projects : 40 +    |    Total Skills : 25 +    |    Languages Known : Hindi and English    |    Website : krishnaportfolio.in    |    Siblings : 3    |    Nationality : Indian    |    Total Experience : 5 Years    |    LinkedIn : https://www.linkedin.com/in/krishna-verma-840b71356/    |    Total Programs : 10000    |    Total Projects : 40    |    Total Skills : 25    |    Total Experience : 5    |    Total DSA Problems : 165    |    Total Served Companies : 2