Posts

Showing posts from 2023

unit testing

  /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable no-unused-expressions */ import { ComponentFixture , TestBed } from '@angular/core/testing' ; import { Store } from '@ngrx/store' ; import { CaseIndicatorConfigurationComponent } from './case-indicator-configuration.component' ; import { UserPreferencesCommonService } from '../services/common.service' ; import { provideMockStore } from '@ngrx/store/testing' ; import { CommonModule } from '@angular/common' ; import { HttpClientTestingModule } from '@angular/common/http/testing' ; import {   ReactiveFormsModule ,   FormsModule ,   FormGroup ,   FormControl ,   Validators , } from '@angular/forms' ; import { RouterTestingModule } from '@angular/router/testing' ; import { OneWebComponentsAngularModule } from '@one/angular' ; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ; import { of } f...

angular search pipe

  import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ({   name : 'searchFilter' , }) export class SearchFilterPipe implements PipeTransform {   transform ( items : any [], searchText : string ): any {     if (! items ) {       return [];     }     if (! searchText ) {       return items ;     }     const searchTextLowerCase = searchText . toLocaleLowerCase ();     return items . filter (( item ) => {       return item . name . toLocaleLowerCase (). includes ( searchTextLowerCase );     });   } } in html use like this *ngFor = "let listItem of templateData | searchFilter: searchText"

sorting in angular 14

 based on pipe sorting import { Pipe , PipeTransform } from '@angular/core' ; export type SortOrder = 'asc' | 'desc' ; @ Pipe ({   name : 'tableSorting' }) export class TableSortingPipe implements PipeTransform {         public sortByTab :   any ;   transform ( value : any [], sortOrder : SortOrder | string = 'asc' , sortKey ?: any ): any {     let sortArrayData = value ;       this . sortByTab = ( a : any , b : any ) => {       const isNumber = ( v : any ) => Number ( v ). toString () === v ;       const aPart = a [ sortKey ]. toString (). match ( /\d + | \D + / g );       const bPart = b [ sortKey ]. toString (). match ( /\d + | \D + / g );       let i = 0 ;       const len = Math . min ( aPart . length , bPart . length );       while ( i < len && aPart [ i ] === bPart [ i ]) { ...