Skip to content

Conversation

itzg
Copy link

@itzg itzg commented Dec 21, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant