gpt4 book ai didi

javascript - 从 Directive AngularJS 调用函数

转载 作者:行者123 更新时间:2023-11-28 18:48:21 26 4
gpt4 key购买 nike

我正在尝试调用指令内的函数。这是一个 html:

<span class="delete-link">
<delete></delete>
<input type="button" data-ng-click="removeRow(task)"/>
</span>

这是指令:

.directive('delete', function() {
return {
restrict: 'E',
replace: true,
template: '<div></div>',
link: function(scope, element) {
element.click(function(){
$scope.removeRow = function (task) {
$scope.tasks.splice($scope.tasks.indexOf(task), 1);
}
});
}
}
});

这是我使用的示例:

http://jsfiddle.net/mrajcok/T96Zu/

但它不会删除元素。我缺少什么?

最佳答案

.directive('delete', function() {

return {

restrict: 'E',
replace: true,
template: '<div></div>',

link: function(scope ,element) {

scope.removeRow = function (task) {
scope.tasks.splice(scope.tasks.indexOf(task), 1);
}

}

}

});

关于javascript - 从 Directive AngularJS 调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34943159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com