javascript - 从多个 Controller 更新页面部分的最佳方式?

标签 javascript html angularjs

我有一个包含 2 个 Controller 的网页(使用 AngularJS)。第一个管理导航栏和页面标题。第二个 Controller 管理消息(或页面的任何其他部分)。使用给定字符串“通知”第一个 Controller 更新页面标题的最佳方式是什么?

最佳答案

使用事件消息传递,点击导航栏上的按钮将触发 emit(),在第二个 Controller 中注册到 on() 的事件处理程序将响应触发器。

$rootScope.$emit() 和 $rootScope.$on()

Working with $scope.$emit and $scope.$on

请注意,它在根作用域上调用 emit/on,所有子级都可以发布订阅。

关于javascript - 从多个 Controller 更新页面部分的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31236705/

相关文章:

javascript - 如何更改当前页面链接的颜色 - HTML/CSS/JavaScript

html - 将鼠标悬停在饼图分段上(纯 CSS)

javascript - AngularJS 指令回调函数计时问题

javascript - 如何禁用 TestCafe cookie 处理机制以允许默认浏览器 document.cookie 列表?

javascript - jQuery 不向服务器发送 Cookie

javascript - Angular.js ng-focus 和 ng-bind 表达式

html - 如何一致地自定义表组

javascript - 在页面底部加载站点

angularjs - 我将如何使用 AngularJs 模拟 Jasmine 的 then() 响应测试

javascript - 带有谷歌地图的AWS服务器