I have a signalrservice(websocket program from .net) which broadcasts the
function from the controller. The handler function is working perfectly
when i use $scope, but i wanted to use the controllerAs syntax how can we
do it?
My angular service, which accepts the websocket messages
app.register.service('SignalRService', function ($, $rootScope) {
var initialize = function () {
//some code to get the connection removed for simplicity
//Starting connection
//Publishing an event when server pushes a greeting message
this.proxy.on('getDeviceData', function (message) {
console.log(message)
//$rootScope.$emit("handleSignalR", message);
$rootScope.$broadcast("handleSignalR", message);
});
}
The event handler function in my controller
POSapp.controller("SalesController", SalesController);
SalesController.$inject = [ 'SignalRService']
function SalesController(SignalRService, $rootScope) {
var vm = this;
//this one works
$scope.$parent.$on("handleSignalR", function (e, message) {
console.log(message);
}
//this one do not works "$on not available on undefined", there is no
$parent available for vm
vm.$parent.$on("handleSignalR", function (e, message) {
console.log(message);
}
}
--
You received this message because you are subscribed to the Google Groups
"AngularJS" 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 http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.