3

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

1 Answer 1

4

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;
    });
}]);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.