Home > Mobile >  ng for loop using ngif condition true false bots condition are same
ng for loop using ngif condition true false bots condition are same

Time:07-08

i m trying to solve my problem if my condition true so return true if my condition false so return false but currently if those only one condition true so all condition apply true please solve my problem

this is my angular ts file code

OfferMatching() {
    this.getmatchoffer.filter(obj => {
      debugger
      for (let i = 0; i < this.applicationJobList.length; i  ){
        var Options = { hour12: false };
        const offerStartDate = new Date(this.applicationJobList[i].offerSteps.initial.jobDateoffer).toLocaleDateString();
      const offerStartTime= new Date(this.applicationJobList[i].offerSteps.initial.startTime).toLocaleTimeString('it-IT',Options);
      const offerEndTime = new Date(this.applicationJobList[i].offerSteps.initial.endTime).toLocaleTimeString('it-IT',Options);
     const bookDateoffer = new Date (obj.offerSteps.initial.jobDateoffer).toLocaleDateString() ;
     const bookstartTime = new Date(obj.offerSteps.initial.startTime).toLocaleTimeString('it-IT',Options);
     const bookendTime = new Date(obj.offerSteps.initial.endTime).toLocaleTimeString('it-IT',Options);
        debugger

         if (bookDateoffer === offerStartDate ) {
          if (bookstartTime  < offerStartTime) {
            if (bookendTime < offerEndTime) {
         return  this.samemOffer = false;
           } else {
         return  this.samemOffer = true;
           }
          } else if (bookstartTime > offerEndTime) {

            if (bookendTime > offerEndTime) {
           return  this.samemOffer = false;

           } else {
           return this.samemOffer = true;
          }
           } else {
          return this.samemOffer = true;
            }
        }
      }

    })

  }

this is my html code

<div  *ngFor="let offerApplication of applicationJobList >
    <i *ngIf="samemOffer">
                                  hello
                                  <span><i  (click)="reCounterOfferAccept(offerApplication)"
                                    title="Accept nhe a"></i></span><br>
                            <span><i  (click)="reCounterOfferDecline(offerApplication)"
                                    title="Decline"></i></span>
                                </i>
                                <i *ngIf="!samemOffer">
                                  by
                                  <span><i  (click)="reCounterOfferAccept(offerApplication)"
                                    title="Accept aja"></i></span><br>
                            <span><i  (click)="reCounterOfferDecline(offerApplication)"
                                    title="Decline"></i></span>
                                </i>
</div>

CodePudding user response:

It's not working as you expect because you are not checking a condition. You are assigning the value true/false to your this.samemOffer, so it will simply return the newly assigned value (true/false). For checking the return conditionally you should do something like:

return this.samemOffer = true ? true : false;

which in this case if this.samemOffer is true, will return true othrewise will return false.

CodePudding user response:

samemOffer is a global variable that is going to be the same value no matter which offerApplication you are looping through.

probably what you want is something like this:

<i *ngIf="offerApplication.samemOffer">

and then set offerApplication.samemOffer separately for each offer

  • Related