简体   繁体   中英

Refresh array items of scope in angular.js

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM