[英]How to find out why ng-click() does not fire second time
I have some code, which works on the jsfidle, and does not work locally. 我有一些代码,该代码可以在jsfidle上运行,而不能在本地运行。 Inside this code I have the directive which compiles template and appends to DOM.
在这段代码中,我具有编译模板并附加到DOM的指令。 Inside this template I bind some ng-click event (close popover).
在此模板内,我绑定了一些ng-click事件(关闭弹出窗口)。 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;
});
}
}
Here the jsFiddle: http://jsfiddle.net/vc4sd1fe/ How I can debug this situation? 这里是jsFiddle: http : //jsfiddle.net/vc4sd1fe/如何调试这种情况? Where could be the problem?
问题可能出在哪里? I am confused why this code perfectly works only once.
我很困惑为什么这段代码只能完美地运行一次。 How can I found wehere to fix it?
我如何找到wehere进行修复?
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.
无论如何,请检查该小提琴以获取更多详细信息,或者我可以将为测试相同代码而创建的html文件发送给您。 It works just fine.
它工作正常。 Th popup is closing on every click.
每次点击都会关闭弹出窗口。
http://jsfiddle.net/Satbir/cswcopgr/ http://jsfiddle.net/Satbir/cswcopgr/
Just deleted some line of code: 刚刚删除了一些代码行:
scope:false,
and directive: 和指令:
<editable></editable>
Please check the same and report me. 请检查相同并报告给我。 It would be great to help you.
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.