サーバーからアイテムのリストを取得するディレクティブがあります。
(関数 () { 'use strict';
angular.module('app').directive('myActionItems', ['ActionService', function (ActionService) {
return {
restrict: 'E',
scope: {
},
controllerAs: "vm",
templateUrl: '/app/home/myActionItems.html',
controller: function ($scope) {
var vm = this;
vm.busy = false;
vm.actions = [];
vm.actionItemChecked = actionItemChecked;
activate();
function activate() {
refresh();
}
function refresh() {
vm.actions = [];
vm.busy = true;
ActionService.getMyActionItems().then(function (result) {
vm.actions = result;
})
.finally(function () {
vm.busy = false;
});
}
function actionItemChecked(action) {
//submit to server to complete it
ActionService.markActionItemComplete(action.id)
.then(function(result) {
//on success remove it from the list.
if (result !== undefined && result != null && result.succeeded) {
vm.actions = _.without(vm.actions, _.findWhere(vm.actions, { id: action.id }));
}
});
}
},
link: function() {
},
};
}]);
})();
「actionItemChecked」メソッドは、各行のボタン クリック (ng-click) を介して html に接続されます。これを配列(および画面)から削除しながら、アニメーションを提供できるようにしたいと考えています。私が理解しているように、DOM操作にはリンクを使用する必要がありますが、いつそれを使用する必要があるかを判断する方法がわかりません。
コントローラーではなくリンクに「actionItemChecked」メソッドを含める必要がありますか? もしそうなら、どのように各行に接続されますか?
私は見てきた
angularjs内のリストのアイテムの追加と削除の両方でjqueryアニメーションをトリガーするディレクティブを使用する方法は?
と
しかし、それを行う方法がわかりません。