Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

javascript - AngularJS/ng-grid - Updating array with splice doesn't updates UI

I am trying to update ng-grid with array splice. I have a plunk here.

Add button adds new row. Update button updates last item in the array.

  1. Select a row & press update button. Nothing happens.
  2. Press add button. Now UI gets updated with new element & as well as the previously updated element.
  3. Same behavior gets repeated again & again.

I tried $scope.$apply. I get:

“Error: $apply already in progress”

I even tried by placing $scope.$apply block inside a setTimeout call. Again the same error!

Any pointers!

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That's because data $watcher in ng-grid (incorrectly) compares the data object for reference, instead on object equality. You might remedy this by setting the third parameter to true in data $watch function (line 3128):

$scope.$parent.$watch(options.data, dataWatcher, true);

Plunker


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...