简体   繁体   English

如何在 angular 8 的同一个 div 中打开两个模态?

[英]how to open two modal in the same div in angular 8?

I have a DIV and in the div, there is a link.我有一个 DIV,在 div 中有一个链接。 Now when I click modalA() .现在,当我单击modalA() It opens modalA() , modalB() and when I click modalB() .它打开modalA()modalB() ,当我单击modalB() It opens modalB() and modalA() .它打开modalB()modalA() because Both methods are in the same div.因为这两种方法都在同一个 div 中。 So When I click modalA() .所以当我点击modalA() It should open modalA() only.它应该只打开modalA() When I click modalB() .当我单击modalB() It should open modalB() only.它应该只打开modalB() please give me your suggesstion.请给我你的建议。

<div class="a" (click)="modalA()">
  <a (click)="modalB()"> </a>
</div>

modalA() {
  console.log('A modal');
}

modalB() {
  console.log('B modal');
}

Use event.stopPropagation使用event.stopPropagation

Try like this:像这样尝试:

modalB() {
  window.event.stopPropagation();
  console.log("B modal");
}

or,或者,

.html .html

<div class="a" (click)="modalA()"> aaaa
  <a (click)="modalB($event)">bbbb </a>
</div>

.ts .ts

modalB(evt) {
  evt.stopPropagation();
  console.log("B modal");
}

Working Demo 工作演示

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

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