perminder-klair / angular-soundmanager2

SoundManager2 Music Player for AngularJs
http://perminder-klair.github.io/angular-soundmanager2/
MIT License
169 stars 108 forks source link

$apply already in progress #42

Open xduseko opened 8 years ago

xduseko commented 8 years ago

This error occurs when angularPlayer service is used and soundManager directive exists on the page.

Example:

  1. Call angularPlayer.addTrack inside ng-click event handler. Note: Every ng-something handler is executed in $apply phase by AngularJS.
  2. Method angularPlayer.addTrack broadcasts player:playlist event.
  3. SoundManager directive catches the event.
scope.$on('player:playlist', function(event, data) {
    scope.$apply(function() {
        scope.playlist = data;
    });
});

Note: We are still in $apply phase, because angular events are handled synchronously.

  1. Error occurs
Error: [$rootScope:inprog] $apply already in progress

The plunker is here http://plnkr.co/edit/77Fy0oJpvRrPrmG1YRbR?p=preview.

xduseko commented 8 years ago

Pull request https://github.com/perminder-klair/angular-soundmanager2/pull/43

elprup commented 8 years ago

I have the same problem, solved by xduseko's fix, thanks.