Search code examples
angularjsangularjs-directiveangularjs-scope

angular.js broadcast error: $rootScope.broadcast is not a function


I am adding items dynamically to an array of items and would like to let a directive know that there are new items. So inside the controller function addItem() I am trying to do the following:

setTimeout(function(){
    $rootScope.broadcast("itemAdded");
    // I also tried: $scope.broadcast("itemAdded"); which isn't working
});

Problem: I'm getting the error:

$rootScope.broadcast is not a function


Solution

  • Its a typo its :

    $rootScope.$broadcast(name, args)