AngularJS - AlertFactory 打开对话框行为 [英] AngularJS - AlertFactory open dialog behavior
问题描述
我正在创建一个 AlertFactory,因为 ui.bootstrap.dialog 在我的应用中不起作用.
i'm creating an AlertFactory because ui.bootstrap.dialog doesn't works in my app.
所以我输入以下代码:http://jsfiddle.net/Premier/BHqKB/17/
enter code here
如果您单击打开对话框"按钮,效果会很好:屏幕上会出现一个包含我的消息的对话框.
It works very well if you click on the "Open dialog" button: on screen appear a dialog with my messages.
我还在 keydown 上注册了一个监听器:监听器触发一个广播事件,在该事件上注册了一个与作用域相关的函数.此函数调用 openDialog 来显示对话框.通过这种方式,angular 不会插入参数,并且使用 {{title}} 占位符显示警报.
I also register a listener on keydown: listener fires a broadcast event on which is registered a scope related function. This function calls openDialog to show the dialog. In this way angular doesn't interpolates arguments and alert is shown with {{title}} placeholder.
我的代码有什么问题?
谢谢.
推荐答案
您需要一个 $apply
来调用摘要循环.
You need an $apply
to invoke a digest cycle.
ng.element(document).on('keydown', function(e){
//alert('keydown');
//openDialog();
$rootScope.$broadcast('openDialog');
$rootScope.$apply();
});
这篇关于AngularJS - AlertFactory 打开对话框行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!