ng-stomp icon indicating copy to clipboard operation
ng-stomp copied to clipboard

Provide option to invoke callbacks within Scope.$apply

Open itzg opened this issue 8 years ago • 0 comments

This introduces a new $stomp.setScopeApply(apply) option to simplify subscription callbacks that are making $scope content changes.

Here is an example of using this option:

.controller('MyCtrl', function ($scope, $stomp) {

    $stomp.setScopedApply(true);
    $scope.currentTime = 0;

    $stomp.connect('/ws', {})
        .then(function(frame){
            var subscription = $stomp.subscribe('/user/exchange/amq.direct/current-time', function(payload, headers, res){
                $scope.currentTime = payload.value;
            })
        })

})

It needs to be an opt-in feature since any existing users of ng-stomp might already be using $scope.$apply and recursive use causes the Angular error: angular.js:14110 Error: [$rootScope:inprog] http://errors.angularjs.org/1.5.9/$rootScope/inprog?p0=%24apply

itzg avatar Dec 21 '16 16:12 itzg