使用 angular 1.2 中的指令打开引导模式 [英] Open a bootstrap modal with a directive in angular 1.2

查看:23
本文介绍了使用 angular 1.2 中的指令打开引导模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 angular-ui bootstrap 来显示模态窗口.我想把它变成一个指令,让我从服务器中提取内容并以模式或弹出框显示......

I'm using angular-ui bootstrap to show modal windows. I'd like to turn this into a directive that would let me pull content from the server and display it in a modal or popover…

例如:<a a-infobox="modal" href="#/content/one">一个链接</a>应该从href中获取内容并拉取它进入模态窗口.

For example: <a a-infobox="modal" href="#/content/one">A link</a> should get the content from the href and pull it into a modal window.

我整理了一个 plunkr:http://plnkr.co/edit/cwtTHjMsW0knlsq2NNtg?p=预览.第一个链接具有 a-infobox 属性.当我点击它时,没有出现对话框.在控制台中你可以看到它被调用了.

I pulled together a plunkr: http://plnkr.co/edit/cwtTHjMsW0knlsq2NNtg?p=preview. The first link has the a-infobox attribute. When I click on it no dialog shows up. In the console you can see that it was called.

当我单击从控制器调用的第二个链接时,它会打开第二个对话框.然后,当我单击该模式上的按钮时,它会消失,并且第一次单击的对话框就在其后面.

When I click on the second link which is called from a controller, it opens the second dialog. Then when I click the button on that modal, it disappears and the dialog from the first click is right behind it.

我刚刚开始深入研究指令,我确信我错过了一些基本的东西.提前致谢.

I'm just starting to dig into directives and am sure I'm missing something fundamental. Thanks in advance.

推荐答案

我找到了一个解决方案...看来需要应用模态,所以 angular 会在下一个摘要中处理它.

I found a solution...it appears that the modal needs to be applied so angular will process it on the next digest.

简单的一行:scope.$apply($rootScope.dlg); 就够了.

A simple line: scope.$apply($rootScope.dlg); is all it took.

plunker 已相应更新.

The plunker was updated accordingly.

这篇关于使用 angular 1.2 中的指令打开引导模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆