2017-08-02 36 views
2

我想知道当我在这里使用这个Pubnub函数时,我可以如何路由到不同的视图。Pubnub AngularJS hereNow函数 - 路由到不同的视图?

QueueController

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

所以基本上我是从这个hereNow功能,然后在内部的算法经过一个条件得到response,我希望它从我的QueueController去我ChatController如此用户可以开始聊天!我甚至从函数中移除了算法,并且仅仅通过了路由,但它根本不起作用。

当我将$location.path('/chat')放在我的hereNow函数的之外时,它确实路由得非常好。

那么如何在这种情况下路线不同的看法?

+0

我认为你需要的功能参数传递$位置,然后它会为你的答案工作 –

+0

你好古拉姆感谢! – Student22

+0

我的祝福:) –

回答

2

刚刚发现this answer,它似乎工作!

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

我加入了$rootScope作为依赖于我的QueueController

app.controller('QueueController', ['$scope', '$location', '$rootScope', 'languageService', 'Pubnub', 
    function($scope, $location, $rootScope, languageService, Pubnub){ ... }]);