Q:

AngularJS: ngRepeat doesn't have time to update before new change happens

$scope.add = function(){

      $scope.playerCards.push(Deck.drawCard());

      if (playerScore > 21){
        console.log("You Busted!");
        newHand();
      }

 };

In this blackjack game, the DOM automatically updates to reflect the players hand using ngRepeat. However, there isn't a window of time to allow the last card to show before the >21 logic executes. I'm guessing angular doesn't have time to run through ng-repeat. How can I force it to update as soon as the data updates? I tried $scope.$digest() but it throws an error about about something else being in progress.

A:

I'd solve that by delaying the test for going over 21, akin to the human delay of adding the cards and seeing they're bust. Maybe even give them enough time to see it for themselves before you tell them. :)

