Monday 10 June 2024

Null check condition with object of object in ngModel in HTML in Angular

 Null check condition with object of object in ngModel in HTML in Angular

[(ngModel)] = "kodingAttittude?.Employee && kodingAttitude?.Employee.Name"

<input formControlName="empName"
            [(ngModel)]="kodingAttitude?.Employee && kodingAttitude?.Employee.Name">

Monday 1 April 2024

Custom Validator for Whitespace and Nextline in Textboxes in Angular

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, AbstractControl, ValidationErrors, Validators } from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
 
  studentForm!: FormGroup;
 
  constructor(private formBuilder: FormBuilder){
   
  }
  ngOnInit(): void{
     this.studentForm = this.formBuilder.group({
        studentName: ['',[Validators.required, this.checkWhitespaceNextlineValidator()]],
        studentMarks: ['',[Validators.required, this.checkWhitespaceNextlineValidator()]]
     });
  }

  checkWhitespaceNextlineValidator(){
    return (control: AbstractControl): ValidationErrors | null => {
      const isNewline = control?.value?.replaceAll(/&lt;,*?&gt;/g, "")?.replaceAll(/<.*?>/g, "");
      const isWhitespace = (isNewline || '').trim().length === 0;
      return isWhitespace ? { whitespace: true } : null;
    }
  }
}

Restrict API Hitting Multiple times to 1 time on page load in Anuglar

import { Component, OnInit } from '@angular/core';
import { ApiService } from '../services/api-service.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
 
  apiTimer: any;

 
  constructor(private apiservice: ApiService){
   
  }
  ngOnInit(): void{
     this.selectDropdown();
     this.searchClick();
  }

  selectDropdown() {
    if(!this.apiTimer){
      this.apiTimer = setTimeout(() => {
       this.getApiResult();
      }, 0);
      }
  }
  searchClick(){
    if(!this.apiTimer){
      this.apiTimer = setTimeout(() => {
       this.getApiResult();
      }, 0);
      }
  }
  getApiResult(){
    this.apiService.getApiResult(request: any).subscribe((data: any) => {
      this.result = data.result;
      if(this.apiTimer){
        this.apiTimer = undefined;
      }
    });
  }
 
}

Saturday 27 January 2024

to return the mock data from Observable in angular service

//to return the mock data from Observable in angular service
//Generic type 'Observer<T>' requires 1 type arguments(s).
getStudentSubjectDropdown(studentID: string): Observable<dropDownData[]> {
    //const params = new HttpParams().append('studentId', studentID);
    //return this.http.get<dropDownData[]>(this.rootURL + 'Student/StudentSubject', { params }).pipe(retry(3));
    let data: dropDownData[] = [
      {
        "id": "1001",
        "name": "Telugu",
        "description": "Telugu is First Language"
      },
      {
        "id": "1002",
        "name": "Hindi",
        "description": "Hindi is Second Language"
      },
      {
        "id": "1003",
        "name": "English",
        "description": "English is Third Language",
      },
      {
        "id": "1004",
        "name": "Mathematics",
        "description": "Maths is a subject"
      },
      {
        "id": "1005",
        "name": "Science",
        "description": "Science is a subject"
      },
      {
        "id": "1006",
        "name": "Social",
        "description": "Social is a subject"
      }
    ],
    return new Observable(( observer: Observer<dropDownData[]>) => {
    observer.next(data);
    observer.complete();
  });

Thursday 29 June 2023

to return the mock data from Observable in angular service

 to return the mock data from Observable in angular service

Error Message: Generic type 'Observer<T> requires 1 type argument(s)

getDropdownData(request: string): Observable<DropdownData[]>{

const params = new HttpParams().append('request', request);

return this.http.get<DropdownData[]>(this.rootURL +'Home/DropdownData', { params });

let data: DropdownData[] = [

{

'label': 'Circle',

'Id': '10'

},

{

'label': 'Rectangle',

'Id': '20'

},

{

'label': 'Triangle',

'Id': '30'

},

{

'label': 'Pentagone',

'Id': '40'

}

];

return new Observable((observer: Observer<DropdownData[]>) => {

observer.next(data);

observer.complete();

});

}

Tuesday 30 March 2021

ORA-02291: integrity constraint (DESIGNATION_EMPLOYEE_FK) violated - parent key not found

 DesignationId column value of EMPLOYEE table should exists in DESIGNATION table while inserting the data in EMPLOYEE table

Sunday 11 October 2020

Severity Code Description Project File Line Suppression State Error MSB3027 Could not copy "obj\Debug\netcoreapp2.1\KodingAttitudeApp.dll" to "bin\Debug\netcoreapp2.1\KodingAttitudeApp.dll". Exceeded retry count of 10. Failed. The file is locked by: ".NET Core Host (9280)" KodingAttittudeApp C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 4194

 Severity Code Description Project File Line Suppression State Error MSB3027   Could not copy "obj\Debug\netcoreapp2.1\KodingAttitudeApp.dll" to "bin\Debug\netcoreapp2.1\KodingAttitudeApp.dll". Exceeded retry count of 10. Failed. The file is locked by: ".NET Core Host (9280)" KodingAttittudeApp C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 4194


To resolve this issue 

1. Close the Visual Studio Application and 

2. Delete the obj and bin folders

if unable delete the bin folder and gets the error dialog box with Try again or Skip

"The action can't be completed because the file is open in dotnet.exe"

3. then go to Task Manager from the Task bar and select .NET Core Host and click on End task button. The the issue will be resolved