简体   繁体   English

Angular 中的 Bootstrap4 模态

[英]Bootstrap4 Modal in Angular

I want to popup bootstrap4 modal window on Angular when my condition in booktour method is true, not by directly clicking the button.当我在 booktour 方法中的条件为真时,我想在 Angular 上弹出 bootstrap4 modal window,而不是直接单击按钮。 How should I do it?我该怎么做? My code is below我的代码如下

html
<div class="modal" id="myModal" [ngClass]="{show: showModalError}">
       <div class="modal-dialog">
         <div class="modal-content">
           <div class="modal-header">
             <h4 class="modal-title">Sorry</h4>         
           </div>

           <div class="modal-body">
             Exceeded the maximum number of tour participants!
           </div>

           <div class="modal-footer">
             <button type="button" class="btn btn-danger" data-dismiss="modal" (click)="showModalError=false">Close</button>
           </div>
         </div>
       </div>
</div>

<button class="btn btn-primary" (click)="bookTour()" > Book</button>

and ts file和 ts 文件

 bookTour() {
    if (this.curPersonNumber + this.number_of_persons > this.tourPersonNumber){
      this.showModalError = true;
    } else {
         this.showModalError = false;
         const bookingRequest = this.bookingForm.getRawValue() as BookingRequest;
         this.bookingService.bookTour(bookingRequest, this.tourId, this.tourDetailId).subscribe(perf => {
         this.router.navigateByUrl('/account');
         });
      }

  }
}

You had to write你必须写

[ngClass]="{'show': showModalError}" (you forgot to put '' to show css class)

and in css并在 css

.show {
   display:block;
}

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

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