简体   繁体   English

角 | Bootstrap - 模态不显示

[英]Angular | Bootstrap - Modal not showing

<img id="1" data-toggle="modal" data-target="#myModal" data-dismiss="modal" src='assets/barrel.jpg' alt='Text dollar code part one.' />
<div id="myModal" class="modal fade" *ngIf="isModalShowing">
  <div class=" modal-lg center">
    <div class="modal-header">
      <button type="button" class="close" (click)="toggleModal()">&times;</button>
      <div class="modal-content">
        <div class="modal-body">
          <img id="1" src="assets/barrel.jpg" class="img-responsive">
          <img id="2" src="assets/car.jpg" class="img-responsive">
        </div>
      </div>
    </div>
  </div>
</div>

Above is my html, nothing happens when I click on the image that I am using as my modal trigger.上面是我的 html,当我单击用作我的模式触发器的图像时,没有任何反应。 This started when I add the ngIf="isModalShowing" function.这是在我添加 ngIf="isModalShowing" 函数时开始的。 Below is my typescript.下面是我的打字稿。

import { Component, OnInit, ViewChild } from '@angular/core';
import { NgModule } from '@angular/core';

@Component({
  selector: 'app-portfolio',
  templateUrl: './portfolio.component.html',
  styleUrls: ['./portfolio.component.scss']
})
export class PortfolioComponent implements OnInit {

  constructor() { }

  public ngOnInit() {

  }

  isModalShowing: boolean;

  toggleModal() {
    this.isModalShowing = !this.isModalShowing;
  }

}

This might help you as you are using pure bootstrap .当您使用纯 bootstrap 时,这可能会对您有所帮助。

pay attention to [ngClass] in app.component.html file注意app.component.html文件中的[ngClass]

I added modal-backdrop class to the class list that gives a visual indication of an active modal.我在类列表中添加了modal-backdrop类,它给出了一个活动模态的视觉指示。

https://stackblitz.com/edit/angular-jggbzx https://stackblitz.com/edit/angular-jggbzx


Or else use ng-bootstrap that has better ways of doing this或者使用ng-bootstrap有更好的方法来做到这一点

Documentation文档

https://ng-bootstrap.github.io/#/components/modal/examples https://ng-bootstrap.github.io/#/components/modal/examples

Running Example运行示例

https://stackblitz.com/edit/angular-dwqv1u https://stackblitz.com/edit/angular-dwqv1u

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

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