2

I'm wondering how I can route to a different view when I'm working with this Pubnub function here.

QueueController

Pubnub.hereNow(
    {
        includeUUIDs: true,
        includeState: true
    },
    function (status, response){
        console.log(response);
        //do some algorithm with response
        $location.path('/chat');
    }
);

So basically I'm getting the response from this hereNow function and then when the algorithm passes a condition inside, I want it to go from my QueueController to my ChatController so the users can begin chatting! I even removed the algorithm from the function and had the route just by itself, but it doesn't work at all.

When I put the $location.path('/chat') outside of my hereNow function, it does route very nicely.

So how does one route to a different view in this case?

Student22
  • 1,979
  • 5
  • 22
  • 33

1 Answers1

2

Just discovered this answer and it seems to be working!

Pubnub.hereNow(
    {
        includeUUIDs: true,
        includeState: true
    },
    function (status, response){
        console.log(response);
        $rootScope.$apply(function(){
            $location.path('/chat');
        });
    }
);

I added the $rootScope as a dependency in my QueueController

app.controller('QueueController', ['$scope', '$location', '$rootScope', 'languageService', 'Pubnub',
    function($scope, $location, $rootScope, languageService, Pubnub){ ... }]);
Student22
  • 1,979
  • 5
  • 22
  • 33