Add list of items to Angular JS array?

So we know that the code below works:

  $http({ method: 'POST', url: url_getMoreHouse })
        .success(function (data) {
                    alert('Works');
                    console.log(data);

                       $scope.HouseBasket = data;
                });

However, if we want to add data to the current basket, which:

         $scope.HouseBasket += data;

This will lead to errors, I do not want to use the foreach loop for push () for each of the data in the $ area. Is HouseBasket a faster way to add a list of objects to an angular list?

+4
source share
1 answer

is there a faster way to add a list of objects to an angular list

? , , , , while, ( ) .

$scope.HouseBasket + = ;

array.concat $scope.HouseBasket = $scope.HouseBasket.concat(data);


, : -

function.apply, .

     [].push.apply($scope.HouseBasket, data);

     $scope.HouseBasket = $scope.HouseBasket.concat(data);
+9

All Articles