angularjs - angular.js广播错误: $rootScope.广播不是函数

标签 angularjs angularjs-directive angularjs-scope

我正在动态地将项目添加到项目数组中,并想让指令知道有新项目。因此,在 Controller 函数 addItem() 内,我尝试执行以下操作:

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

问题: 我收到错误:

$rootScope.broadcast is not a function

最佳答案

这是一个错字:

$rootScope.$broadcast(name, args)

关于angularjs - angular.js广播错误: $rootScope.广播不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16213684/

相关文章:

angularjs - 模板内的嵌套指令放置在顶部

javascript - Angularjs 确认密码指令 : why it does not see keyboard inputs?

javascript - AngularJS : Expose ng-repeat scope to ng-transclude

javascript - AngularJS 1.x 在 ng-repeat 中一次显示一项,单击下一步应显示下一项,依此类推

javascript - AngularJS 在 ng-change 调用的函数中将属性值作为参数传递

javascript - 如何使用 AngularJS 定期轮询远程 json?

javascript - 如何在同级组件指令之间传递事件

angularjs - 如何使用 karma 和 jasmine 测试 screen.width 条件

javascript - AngularJS 入门失败

javascript - 如何在 Angular 列中使用ng-repeat?