如何找出为什么NG-点击()不会触发第二次 [英] How to find out why ng-click() does not fire second time

查看:128
本文介绍了如何找出为什么NG-点击()不会触发第二次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code,它作用于jsfidle,并没有在本地工作。
这里面code我有一个编译模板,并追加到DOM的指令。这里面我的模板绑定一些NG-click事件(接近酥料饼)。此事件被触发一次,并且当上了第二次,并试图将其关闭开酥料饼,这是行不通的。
在这里,code:

I have some code, which works on the jsfidle, and does not work locally. Inside this code I have the directive which compiles template and appends to DOM. Inside this template I bind some ng-click event (close popover). This event fired once, and when open popover on the second time and trying to close it, it does not work. Here the code:

mymodal.directive('editable', function ($compile) {
    return {
        restrict: 'EAC',
        template: "<a href='#' id='pop-over-link'>Show pop-over</a>",
        scope: {test: '&'},
        link: function(scope, element, attrs) {
            scope.closePopover = function($event){
              var el = $event.target;
                     $($event.target).parents('div.popover').popover('hide');
          };
          var templateData = 
            "<button class='btn btn-default btn-sm cancel' ng-click='closePopover($event)'>Cancel</button>";

          var compliedData = $compile(templateData)(scope);

          $(element)
            .popover({html: true,
                      content: compliedData
                     })
            .on('click', function(e) {
              e.preventDefault();
              return true;
            });                                    
        }
    }

在这里的jsfiddle: http://jsfiddle.net/vc4sd1fe/
如何调试这种情况?凡可能是问题?我很困惑,为什么这个code完美的作品只有一次。我怎样才能找到wehere解决它?

Here the jsFiddle: http://jsfiddle.net/vc4sd1fe/ How I can debug this situation? Where could be the problem? I am confused why this code perfectly works only once. How can I found wehere to fix it?

推荐答案

我已经在当地做了一个相同的环境。但没有得到任何问题。反正检查此捣鼓更多详情或我可以给你,我创建的测试相同code中的HTML文件。它的工作原理就好了。个弹出窗口关闭的每次点击。

I have made a same environment on local. But didn't get any issues. Anyway check this fiddle for more details or I can send you the html file that I created to test the same code. It works just fine. Th popup is closing on every click.

http://jsfiddle.net/Satbir/cswcopgr/

刚刚删除code的一些行:

Just deleted some line of code:

 scope:false,

和指令:

<editable></editable>

请检查相同,举报我。这将是巨大的帮助你。

Please check the same and report me. It would be great to help you.

这篇关于如何找出为什么NG-点击()不会触发第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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