Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular ng-app controller inject

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

like image 704
daremachine Avatar asked Apr 08 '26 10:04

daremachine


1 Answers

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;
    });
}]);
like image 88
Liviu T. Avatar answered Apr 09 '26 23:04

Liviu T.