Search code examples
sqlitefirebaseionic3angular-ng-if

ionic 3 *ngf how to set value


I have two loop one from firebase other from SQlite I want to compare the value from each If the value in SQLite and firebase equal I will print the SQlite only and I don't want to print firebase value if the value not equal I will print firebase value only

this is the code

 <div *ngFor="let adv of advlist | async">

   <div *ngFor="let da of data">

      <div  *ngIf="da.key == adv.key? ok = false: ok = true">

        <ion-card style="background-color: #a7acaf">
        <ion-card-content>
         <ion-card-title>
              {{da.orgin}}
         </ion-card-title>
        <p>
          {{da.subject}}
        </p>
        <p><b>from</b> : {{da.startDate}} <b>to</b>:  {{da.endDate}}</p>
        </ion-card-content>
         </ion-card> 
    </div>

  </div>

<ion-card *ngIf="ok" (click)="openfile(adv)">

   <ion-card-content>
    <ion-card-title>
        {{adv.orgin}}
      </ion-card-title>
    <p>
        {{adv.subject}} 
    </p>
    <p><b>from</b> : {{adv.startDate}} <b>to</b>:  {{adv.endDate}}</p>
  </ion-card-content>
</ion-card>      

</div> 

Solution

  • I did it in .ts file using for loop

    newData(){
    
    
    
     let dd = true;
    
    
      if(this.Newdata1.length > 0){
    for(let i = 0;i < this.Newdata1.length ; i ++){
        for(let y = 0 ; y < this.data.length ; y++ ){
          if(this.Newdata1[i].key == this.data[y].key){
            alert('this.Newdata1 5' );
              this.Newdata.push({
                key: this.data[y].key,
                orgin: this.data[y].orgin,
                title: this.data[y].title,
                subject: this.data[y].subject,
                startDate: this.data[y].startDate,
                endDate: this.data[y].endDate,
                fileName: this.data[y].fileName,
                url: this.data[y].url
              });
               dd = false;
              break;
          }
    
        }
    if(dd){
    this.Newdata.push(
    {
      key: this.Newdata1[i].key,
      orgin: this.Newdata1[i].orgin,
      title: this.Newdata1[i].title,
      subject: this.Newdata1[i].subject,
      startDate: this.Newdata1[i].startDate,
      endDate: this.Newdata1[i].endDate,
      fileName: this.Newdata1[i].fileName,
      url: this.Newdata1[i].url
    });
    
    
    }
    
    
    
     dd = true;
    }
    
    }else{
      for(let y = 0 ; y < this.data.length ; y++ ){
    
     this.Newdata.push({
        key: this.data[y].key,
        orgin: this.data[y].orgin,
        title: this.data[y].title,
        subject: this.data[y].subject,
        startDate: this.data[y].startDate,
        endDate: this.data[y].endDate,
        fileName: this.data[y].fileName,
        url: this.data[y].url
      });
    
    
    }  
    }
    
    }