I have a dashboard with fix size of cards(4).Whenever i shift any one card to another position, Duplicate of that same card got created in dashboard. Now I have total 5 cards.If I do this same, again it will create duplicates.My aim is just to move a card to another position without duplication.
In html file
<div class="card"
ng-repeat="card in dashCtrl.cards track by $index"
dnd-draggable="card"
dnd-type="'card'"
dnd-effect-allowed="move"
dnd-moved="dashCtrl.updateCardPosition($index)"
dnd-dynamic-placeholder-size="true" ng-include="'/partials/dashboard/'+card.template+'.html'">
</div>
Here dashCtrl == dashboard_controller
in dashboard controller.
function updateCardPosition($index) {
// if(vm.cards.length!=4)validEntry();
// vm.cards.splice($index, 1);
console.log('dsdsdsdsds',$index);
vm.cards = _.uniqBy(vm.cards,'template');
vm.cards.forEach((ele)=>{
console.log('xxxxxxxxxxxxxx',ele);
});
// console.log("cards",vm.cards.length);
// console.log('index',$index);
Store.set('cards', JSON.stringify(vm.cards));
}
Here vm is object(this) of controller and it has many method. So vm.cards is an array of cards.I used Store(for local storage) to store modified array(in terms of position).
structure of vm.cards
vm.cards = [
{template: 'agenda-card'},
{template: 'budget-card'},
{template: 'collaborate-card'},
{template: 'todo-card'}
];
I checked everything from google but I couldn't find the solution.I guess duplication problem might arise from dnd-draggable.I am just guessing. So how to solve that duplication problem??