Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have an array with x items. I need to copy this items and add a few more, but when I show the items in the ng-repeat I copy the firsts again.

How can I delete the items and put the new in real time? I tried using

delete $scope.items
$scope.items = []

But It not works.

It seems very basic question but I can't find a solution :(

EDIT

In the function when I add new items

$scope.order = function(auxItems){

   var auxTotal = $scope.items;

   auxItems.map(function(bono){
      auxTotal.push(bono);
   });

When I do some some stuff to add the items definitely I return an array.

var bonosOrdenados = $scope.ordena(auxBonos);

bonosOrdenados.map(function(elemento){
   elemento.map(function(bono){
   $scope.items.push(bono);
  })
});

And of course the items are duplicated because I don't knot how to control it.

share|improve this question
    
Show us what you have tried so far. You may add your detail code/plunker/fiddle. – Khalid Hussain yesterday
    
Create a demo using fiddle or pen. – Manwal yesterday

1 Answer 1

Try in your script:

$scope.clear = function () {
    items.length = 0;
}

And in your HTML you call the clear-function with ng-click or somthing else.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.