Reputation: 2788
I have a problem with inject controller for broadcast service...
I found this working tutorial
http://jsfiddle.net/simpulton/GeAAB/
but I have a controller encapsulated like this (myApp)
myApp.controller('ControllerZero',
function ControllerZero($scope, sharedService) {
$scope.handleClick = function(msg) {
sharedService.prepForBroadcast(msg);
};
$scope.$on('handleBroadcast', function() {
$scope.message = sharedService.message;
});
});
and my problem is .. I dont know how I can inject controller like at tutorial before
if I put this inject under my controller
ControllerZero.$inject = ['$scope', 'mySharedService'];
this give me back in console:
Uncaught ReferenceError: ControllerZero is not defined
Upvotes: 3
Views: 2136
Reputation: 23664
You need to use an array to let angular know all controller variables
myApp.controller('ControllerZero', ['$scope', 'mySharedService',
function ControllerZero($scope, sharedService) {
$scope.handleClick = function(msg) {
sharedService.prepForBroadcast(msg);
};
$scope.$on('handleBroadcast', function() {
$scope.message = sharedService.message;
});
}]);
Upvotes: 4