【发布时间】:2015-05-08 02:20:42
【问题描述】:
我在 div 中有一个 amchart,其显示/隐藏由 angularjs 管理。有时它会绘制已经在内存中的数据图表。在这种情况下,会打开 div,渲染图表,并且其中的 SVG 的宽度为 10。因此图表不会出现在屏幕上。调整窗口大小并显示图表,因为我猜 amcharts 正在监听调整大小的事件。我认为这是一个已知问题 - 我已经看到了一些关于它们的 SO 帖子,我希望其中一个对我有用。我的怀疑是,在 amcharts 开始发挥它的魔力之前,角度机器没有得到循环来打开 div(只是一种预感,没有确凿的证据。)
接下来,我添加了一个事件观察器
piechart.write(divs.chart_div.attr('id'));
divs.chart_div.on('yes', 'snowy', function(){ // same with 'shown','resize'
console.info('============= woah ========');
});
现在发生了一件奇怪的事情。我在控制台中看到以下错误堆栈
Error: [jqLite:onargs] jqLite#on() does not support the `selector` or `eventData` parameters http://errors.angularjs.org/1.3.13/jqLite/onargs
at REGEX_STRING_REGEXP (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8762:12)
at jqLiteOn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11733:39)
at Object.JQLite.(anonymous function) (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11951:17)
at Object.makePieChart (http://localhost:8100/common/services/graphinghelperService.js:528:34)
at obj.controller.$scope.myExt.renderFunc (http://localhost:8100/directives/boxRenderers2.js:179:24)
at _render_it (http://localhost:8100/modules/dashboard/dashboard.js:246:30)
at $scope.showBox.deferred.promise.then.workarea.showChild (http://localhost:8100/modules/dashboard/dashboard.js:310:17)
at processQueue (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21888:27)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:21904:27
at Scope.$get.Scope.$eval (http://localhost:8100/lib/ionic/js/ionic.bundle.js:23100:28)
这种时髦的行为已经消失了!如果我单击以从缓存数据中重绘它,图表就会出现,再次单击时隐藏,一切都很好。再也不用盯着平淡无奇的背景色 div 了!!。
但是,如果我将手表更改为divs.chart_div.on('shown', function(){,则不会调用事件处理程序,并且在渲染出缓存数据时图表不会出现。
我想知道发生了什么。
【问题讨论】:
-
A
watch是 Angular 通过“观察”来响应变化数据的能力。您使用的是事件,而不是手表。完全不同的东西。 -
在您的依赖项中包含 jquery,错误清楚地说明了它被抛出的原因。 angular 内部使用 jqLite,它不支持 on 事件的选择器。
-
amCharts 不依赖 jQuery,因此与它是否被加载无关。考虑更新到最新版本的 amCharts 库 (3.14.2),它包含自动监视容器大小/可见性更改(与早期版本中监视窗口大小更改相反)。如果失败,请尝试利用 Angular 的事件并在图表容器显示时在图表对象上调用 invalidateSize()。
-
谢谢。升级会按照建议修改行为,而无需利用任何事件或 invalidateSize()
标签: angularjs ionic-framework amcharts