I have an angularjs app that has several modules. The main modules looks something like:
var app = angular.module('mainMod', ['apiService']);
app.controller('MainCtrl', function (Socket) {
$scope.objects = {};
// do something with $scope.objects, etc.
});
And then I have;
var apiService = angular.module('apiService', ['ngResource']); // etc
and;
apiService.factory('Socket', ['$rootScope', function ($rootScope) {
// create a websocket and listen for stuff
// if something happens, update 'objects' in $rootScope
}]);
The thing is, I see that the service Socket
has been injected in MainCtrl
, but inside the Socket
service, I can not access $rootScope.objects
. I do understand that factories have no scopes of their own, but since its injected into MainCtrl
, shouldn't the rootscope refer to the scope of the MainCtrl
?
There is a workaround using events, but I'm not too keen on that. I have tried it with success but I'd prefer a solution where this just works.