javascript - Highcharts 和 Angularjs : update chart from $broadcast in the main controller doesn't update the chart like a $watch would in the chart's controller

标签 javascript angularjs highcharts

根据请求,我将简化我的问题..但因为它与本地主机上的 API 交互,所以我无法在 jsfiddle 上复制该问题。我将把我的问题分解为主 Controller 和子 Controller 之间发生的事情的细节......

主 Controller :范围包含公司 ID 并使用 get 函数从 API 访问数据。

子 Controller :继承从API返回的对象并将数据注入(inject)到highchart中。该 Controller 还包含一个用于遍历 highchart 中数据的 UI 的 $watchCollection。

我的问题是这样的:当父范围中的公司 ID 发生更改并且 API 获取新数据时,图表不愿意立即更新,因为 $watchCollection 不包含父范围中的内容。

我知道这个想法是将更改 $broadcast 到子 Controller 并进行相应更新,但图表仍然不会更新,直到 UI 上发生更改,从而触发 $watchCollection。

当父范围发生变化时,我该如何强制图表触发 $watchCollection?

最佳答案

子作用域原型(prototype)继承父作用域的属性,因此您应该能够直接 $watch currentCoId 或数据。

另请参阅此 short demo

(请注意, $watchCollection() 仅检测在集合中添加/删除/移动项目,而不查看其内容。)

关于javascript - Highcharts 和 Angularjs : update chart from $broadcast in the main controller doesn't update the chart like a $watch would in the chart's controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22900434/

相关文章:

javascript - 使用 jQuery/JS 时如何使用 <input type=number> 更改 `rect` 框的大小和坐标

javascript - 如何在angularjs中使用ng-repeat在css中动态设置表格列的宽度

javascript - 范围问题 - 在基于类的 Controller 中嵌套 $mdDialog

javascript - angularjs 智能表以编程方式排序

javascript - 如何在 Highcharts 中将面积图颜色更改为高于特定值

javascript - 除非不同的元素在 AngularJS 中具有焦点,否则隐藏元素的最佳方法是什么?

javascript - IE 10,9,8 : Can userAgent be changed through a javascript code?

javascript - RXJS5 像 Promise 一样链接

javascript - Highcharts 3D 饼图

javascript - Highcharts 年龄堆叠