1
我正在生成一个指令,通过包含将链接附加到DIV。现在我想链接被点击时执行一些功能,而不是去我已经包含了虚拟的href(在这种情况下google.com),例如...。由Angular指令生成的链接上的.stopPropagation()与包含
.directive('deleteDiv', function() {
return {
restrict: 'A',
transclude: true,
template: '<a href="http://www.google.com" ng-click="removeDiv()">X</a> ',
link: function (scope, elem) {
// now we don't want the link to go to the href!
scope.removeDiv = function(e){
e.stopPropagation();
console.log(elem); // but we do more things later....
}
}
}
})
当我点击链接,我们对得到一个错误,因为e
是未知的,href
将我们发送到谷歌。即使我将return false;
添加到removeDiv
方法或更改e
对于event
我们仍然会发送到href
位置。 (可能需要一个很好的解释)我如何使这项工作任何想法