Mart..
10
Angular不推荐克隆DOM元素,因为它通常用于拖放操作.相反,克隆您的对象模型.
假设您在一个项目中显示项目,
- 并且只有在拖动时才能看到另一个拖动的项目:
- {{item.text}}
并在控制器中,制作项目的副本以拖动到draggedItem:
$scope.items = [{text:"First"}, {text:"Second"}];
$scope.shadowItem = null; // Item at the original position
$scope.draggedItem = null; // Clone item being moved
$scope.dragStart = function(item) {
$scope.shadowItem = item;
$scope.draggedItem = angular.copy(item);
item.shadow = "shadow"; // set a CSS class to change its look
// From now on, the DIV is dragged around
}
$scope.drop = function() {
// Save the new item position
$scope.draggedItem = null; // Makes the dragged clone item disappear
$scope.shadowItem.shadow = ""; // give the item its normal look back
}