I have chatCtrl.js where consumer subscribes to NotifyChannel.
Also I have mapCtrl.js and a user have to switch between chatCtrl.js and
mapCtrl.js
Problem: when switching from chatCtrl.js to mapCtrl.js, I don't want to
destroy subscription in chatCtrl.js and user should get messages even when
he is in mapCtrl.js
I tried $rootScope.consumer instead of 'var consumer', but it's a bad idea.
I use angular 1.5.11
Here, my
chatCtrl.js
app.run(function (ActionCableConfig){
ActionCableConfig.debug = true;
//ActionCableConfig.wsUri= "ws://localhost:3000/cable";
});
app.controller('chatCtrl', function($scope, myConfig, $routeParams,
ActionCableChannel, ChatService, SharedState, ActionCableSocketWrangler){
var consumer = new ActionCableChannel("NotifyChannel", {user_id:
myConfig.currUser.id} );
var callback = function(message) {
myConfig.chatData.push(message);
};
consumer.subscribe(callback).then(function(){
$scope.sendToMyChannel = function(message){
consumer.send(response.data);
};
$scope.$on("$destroy", function(){
consumer.unsubscribe().then(function(){ $scope.sendToMyChannel =
undefined; });
})
})
});
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.