isContainer - with model
Items1:
{{items1 | json}}
Cart:
{{cartModel | json}}
// JS
.controller('IsContainerModel', ['$scope', '$element', 'dragularService', function TodoCtrl($scope, $element, dragularService) {
$scope.items1 = [{
content: 'Move me, but you can only drop me in one of these containers.'
}, {
content: 'If you try to drop me somewhere other than these containers, I\'ll just come back.'
}, {
content: 'Item 3'
}, {
content: 'Item 4'
}];
$scope.cartModel = [];
var containerLeft = document.querySelector('#containerLeft');
dragularService.cleanEnviroment();
dragularService([containerLeft], {
containersModel: [$scope.items1],
copy: true,
isContainer: function isContainer (el) {
return el.id === 'cart';
},
isContainerModel: function getModel (){
return $scope.cartModel;
}
});
$scope.removeItem = function removeItem() {
var index = $scope.cartModel.indexOf(this.item);
$scope.cartModel.splice(index, 1);
};
}])
<!-- HTML -->
<div class='wrapper' ng-controller="IsContainerModel">
<div class='tableRow'>
<div id="containerLeft" class='containerVertical'>
<div ng-repeat="item in items1">{{item.content}}</div>
</div>
<div id="cart" class='containerVertical'>
<div class='cursorDefault' ng-repeat="item in cartModel">{{item.content}}
<button class='cursorDefault' ng-click="removeItem()">x</button></div>
</div>
</div>
<div class="tableRow">
<div class='containerVertical'>
<pre>Items1:
<br/>{{items1 | json}}</pre>
</div>
<div class='containerVertical'>
<pre>Cart:
<br/>{{cartModel | json}}</pre>
</div>
</div>
</div>