简体   繁体   English

ng for loop 使用 ngif 条件 true false bots 条件相同

[英]ng for loop using ngif condition true false bots condition are same

im 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这是我的角度 ts 文件代码


samemOffer = false;

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这是我的 html 代码

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

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).您正在将值 true/false 分配给 this.samemOffer,因此它只会返回新分配的值 (true/false)。 For checking the return conditionally you should do something like:为了有条件地检查返回,您应该执行以下操作:

return this.samemOffer = true ?返回 this.samemOffer = true ? true : false;真假;

which in this case if this.samemOffer is true, will return true othrewise will return false.在这种情况下,如果 this.samemOffer 为 true,将返回 true,否则将返回 false。

samemOffer is a global variable that is going to be the same value no matter which offerApplication you are looping through. samemOffer 是一个全局变量,无论您循环访问哪个 offerApplication,它都将是相同的值。

probably what you want is something like this:可能你想要的是这样的:

<i *ngIf="offerApplication.samemOffer">

and then set offerApplication.samemOffer separately for each offer然后为每个offer分别设置offerApplication.samemOffer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM