Search This Blog

Thursday, July 21, 2022

splice vs. slice in JavaScript

Reference :  

https://www.educative.io/answers/splice-vs-slice-in-javascript

Angular: conditional class with *ngClass

 Reference:

https://stackoverflow.com/questions/35269179/angular-conditional-class-with-ngclass



One one

[class.my_class] = "step === 'step1'"

type two

[ngClass]="{'my_class': step === 'step1'}"

and multiple option:

[ngClass]="{'my_class': step === 'step1', 'my_class2' : step === 'step2' }"

type three

[ngClass]="{1 : 'my_class1', 2 : 'my_class2', 3 : 'my_class4'}[step]"

type four

[ngClass]="step == 'step1' ? 'my_class1' : 'my_class2'"

Tuesday, July 19, 2022

If else and else if in angular template in html

 if (foo === 1) {


} else if (bar === 99) {

} else if (foo === 2) {

} else {

}

in the template:

<ng-container *ngIf="foo === 1; else elseif1">foo === 1</ng-container>

<ng-template #elseif1>
    <ng-container *ngIf="bar === 99; else elseif2">bar === 99</ng-container>
</ng-template>
<ng-template #elseif2>
    <ng-container *ngIf="foo === 2; else else1">foo === 2</ng-container>
</ng-template>
<ng-template #else1>else</ng-template>



  <ng-container class="f-11" *ngIf="data.dcblWsp ==='' && data.cbrand1Wsp  === '' &&  data.billingPrice ==='0' else wsp">    
                                 
  <li> PD cannot be calculated because no WSP was captured for the district </li>  
  </ng-container>

                                                                 
  <ng-template #wsp>
                                     
  <li *ngIf="data.dcblWsp ==='' else noinvoice"> (Captured WSP - B1 WSP) is ignored as B1 WSP cannot be calculated  </li>
                                     
</ng-template>

<ng-template #noinvoice>
                                     
  <li  *ngIf="data.billingPrice ==='0'"> PD cannot be calculated because no invoices were generated for the district </li>
                                       
  </ng-template>



Reference:

https://stackoverflow.com/questions/43812770/ngif-else-if-in-template

Monday, July 18, 2022

how-to-add-a-property-to-each-object-in-an-array-of-objects-with-javascript

    

   this.pricingDetailData=res["pricedata"]; this.pricingDetailData.forEach((element:any) =>
    {
      let item = {

     
 
     
          "ASO":  [ "497", "26" ,"33", "497", "26" ,"33", "497", "26" ,"33", "50"],
          "TSM" : [ "497", "26" ,"33", "497", "26" ,"33", "497", "26" ,"33", "50"]
     
      }
   
       element.asoTsmData  = item;
    });                          https://thewebdev.info/2021/05/11/ how-to-add-a-property-to-each-object-in-an-array-of-objects-with-javascript/#:~:text=We%20can%20use%20the%20forEach,add%20a%20property%20to%20each.&text=We%20have%20the%20arr%20array,b%20property%20to%20a%20value.&text=according%20to%20the%20console%20log.                                                            

Validating to select in sequencial order using angular

    < input type = "checkbox" (change) = "handleSelectTaskItem($event, taskItem)" [checked] = " taskItem . i...