我有一个建立谷歌图表的指令。当指令从图表中接收到事件时,我希望在控制器的作用域中触发一个事件处理程序。
样本:http://plnkr.co/edit/yn4KuQfrYvlQNbPSWk3Q?p=preview
在我的标记中:
<div column-chart="chartData" row-selected="rowSelected(index)"></div>在我的指令中:
google.visualization.events.addListener(chart, 'select', function () {
console.log('directive#select', chart.getSelection());
// call the function defined in the markup for "row-selected"
});在我的控制器里:
$scope.rowSelected = function (index) {
console.log('controller#rowSelected', index);
// the function I want to ultimately be called
};我能用一个指令做这个吗?图表指令能知道行选择指令吗?如果有什么帮助的话,谢谢。
发布于 2013-12-17 23:09:51
您可以访问范围函数rowSelected。
google.visualization.events.addListener(chart, 'select', function () {
console.log('directive#select', chart.getSelection());
scope.rowSelected(chart.getSelection().row)
});如果不想硬编码rowSelected,可以通过属性传递它,使其更加灵活。
https://stackoverflow.com/questions/20646360
复制相似问题