2

I am using simple array of numbers like below with ng-repeat:

n = [1,2,3,4,5,6]

The issue is, when I change this array for eg:

n=[1,2,3]

It doesn't fully reload the DOM but instead it just remove the last 3 div elements related to array 4, 5, 6. Is there any way to force the ng-repeat to reload DOM everytime I change the array.

5
  • 5
    Why do you want to reload the dom? Commented Jun 11, 2015 at 13:59
  • 5
    That is actually a feature, not a bug. Commented Jun 11, 2015 at 14:00
  • 3
    Thats why AngularJS is such cool, data-binding on MV*. But, what exactly is your problem with this behavior? Commented Jun 11, 2015 at 14:01
  • Actually I am using different layout everytime I change the array. Otherwise ngRepeat doesn't update div element related to first 3 array values. Commented Jun 11, 2015 at 14:23
  • @codelearner, I suggest you add more details about your change of layout objective Commented Jun 12, 2015 at 0:34

1 Answer 1

1

Have you try it change the array into an $apply call?, something like:

$scope.$apply(function() {
    n = [1, 2, 3];
});
Sign up to request clarification or add additional context in comments.

3 Comments

This also doesn't work because according to ngRepeat documentation - Should you reload your data later, ngRepeat will not have to rebuild the DOM elements for items it has already rendered, even if the JavaScript objects in the collection have been substituted for new ones.
This article could help you then: bennadel.com/blog/…
@didando8a Thanks for the link. But I am using simple array of numbers not objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.