在NG-点击确认对话框 - AngularJS [英] Confirmation dialog on ng-click - AngularJS

查看:424
本文介绍了在NG-点击确认对话框 - AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装在一个 NG-点击确认对话框使用自定义angularjs指令:

I am trying to setup a confirmation dialog on an ng-click using a custom angularjs directive:

app.directive('ngConfirmClick', [
    function(){
        return {
            priority: 1,
            terminal: true,
            link: function (scope, element, attr) {
                var msg = attr.ngConfirmClick || "Are you sure?";
                var clickAction = attr.ngClick;
                element.bind('click',function (event) {
                    if ( window.confirm(msg) ) {
                        scope.$eval(clickAction)
                    }
                });
            }
        };
}])

这个伟大的工程,但不幸的是,用我的指令,在标签内的前pressions不评估:

This works great but unfortunately, expressions inside the tag using my directive are not evaluated:

<button ng-click="sayHi()" ng-confirm-click="Would you like to say hi?">Say hi to {{ name }}</button>

(名称不评估是此情况)。这似乎是由于我的指令的终端参数。你有解决办法的任何想法?

(name is not evaluated is this case). It seems to be due to the terminal parameter of my directive. Do you have any ideas of workaround?

要考验我的code:
http://plnkr.co/edit/EHmRpfwsgSfEFVMgRLgj?p=$p$pview

To test my code: http://plnkr.co/edit/EHmRpfwsgSfEFVMgRLgj?p=preview

推荐答案

如果你不介意不使用 NG-点击,它的工作原理确定。您只需重命名为别的东西,仍然读取属性,同时避免了click处理程序被触发两次的问题存在的时刻。

If you don't mind not using ng-click, it works OK. You can just rename it to something else and still read the attribute, while avoiding the click handler being triggered twice problem there is at the moment.

http://plnkr.co/edit/YWr6o2?p=$p$ PVIEW

我认为这个问题是端子指示其他指令不运行。与数据绑定{{}} 仅仅是为 NG-绑定指令,这是$ P $别名通过端子 psumably取消。

I think the problem is terminal instructs other directives not to run. Data-binding with {{ }} is just an alias for the ng-bind directive, which is presumably cancelled by terminal.

这篇关于在NG-点击确认对话框 - AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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