我正在尝试ng-click
使用自定义angularjs指令在上设置确认对话框:
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)
}
});
}
};
}])
这很好用,但不幸的是,未评估使用我的指令的标记内的表达式:
<button ng-click="sayHi()" ng-confirm-click="Would you like to say hi?">Say hi to {{ name }}</button>
(这种情况下不评估名称)。这似乎是由于我的指令的终端参数。您有解决方法的想法吗?
要测试我的代码:http : //plnkr.co/edit/EHmRpfwsgSfEFVMgRLgj?p=preview