这是一个工作示例,这使在指令范围内的两者之间移动的方法保持不变。然而,不是有箭头(不确定你的意思,即只移动底部元素,或者每个箭头,或者什么),你只需点击一个元素来移动它。
myApp.directive('duallist', function() {
return {
restrict: 'E',
replace: true,
scope: {
data1: '=',
data2: '='
},
template: '<div><ul class="list"><li ng-repeat="datum in data1" ng-click="move(datum, data1)">{{datum}}</li></ul> <ul class="list"><li ng-repeat="datum in data2" ng-click="move(datum, data2)">{{datum}}</li></ul></div>',
link: function(scope, ele, attrs) {
scope.move = function(datum, dataset) {
if (dataset == scope.data1) {
scope.data2.push(datum);
dataset.splice(dataset.indexOf(datum), 1);
}
else{
scope.data1.push(datum);
dataset.splice(dataset.indexOf(datum), 1);
}
}
}
}
});
工作小提琴:http: //jsfiddle.net/joshdmiller/HB7LU/