Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  165] [ 6]  / answers: 1 / hits: 91846  / 9 Years ago, wed, april 22, 2015, 12:00:00
 $scope.itemarray = ['A', 'B', 'C'];  


this will clear the array but the ui wont be updated.



$scope.itemarray = [];


this works fine! why?



 $scope.itemarray.length = 0;  

More From » angularjs

 Answers
64

$scope.itemarray.length = 0; << this is correct. Length is read-write property.



$scope.itemarray = []; << this creates new empty array. If you have bindings to old itemarray, they may be lost. (Html binding like ng-if=itemarray[0] wont be lost)


[#66951] Tuesday, April 21, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamila

Total Points: 490
Total Questions: 94
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;