简体   繁体   English

UI Bootstrap模式在指令 - 多个模态中,但只打开一个

[英]UI Bootstrap modal in directive- multiple modals but only one opens

As seen in this Plunkr , I have two modals, each in separate directive of modal-one and modal-two . 正如在这个Plunkr中所看到的,我有两个模态,每个模态在modal-onemodal-two单独指令中。

The problem is, that only modal one is being opened, even when clicking on modal two button. 问题是,即使单击模态2按钮,也只打开模态1。

I guess that it has something to do with the .open method on the $scope is overwritten? 我猜它与$scope上的.open方法有关被覆盖了吗?

How do I prevent it? 我该如何预防呢? Thank you! 谢谢!

Basically behind the scene you are sharing a single scope amongest both the directive, as you don't have scope property inside directive, it sets to false (it will share up the scope). 基本上在场景后面你共享一个范围最长的指令,因为你没有指定scope内的scope属性,它设置为false (它将共享范围)。 So when first directive gets loaded it registers $scope.open method with popup code. 因此,当第一个指令被加载时,它会使用弹出代码注册$scope.open方法。 And when the other directive renders it takes same scope and override $scope.open method. 当另一个指令呈现时,它采用相同的范围并覆盖$scope.open方法。

You could easily fix this issue by making your directive scope to use scope: true / scope: {} 您可以通过使指令范围使用scope: true来轻松解决此问题scope: true / scope: {}

Working Demo 工作演示

Else you could share the same scope, but then you need to change the method name in one of two directive. 否则,您可以共享相同的范围,但是您需要在两个指令之一中更改方法名称。

Other Demo 其他演示

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

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