我不知道是否有处理的角谷歌图表API事件的好办法?
(没有足够的口碑,使这些引用正确的链接:)
我使用[bouil.github.io/angular-google-chart/]
并试图端口[github.com/angular-ui/ui-map/blob/master/ui-map.js]
的处理与[github.com/angular-ui/ui-utils/blob/master/modules/event/event.js]事件的方式。
这里是表示非交互图的plunker:
http://plnkr.co/edit/RTx8UgZdEvDmYoPUu4Xf
我想发生的是把foo() - 在选择图表中由方法(显示警报)将被调用。
模板:
<div data-google-chart chart="chart" class="chart" ui-event="{'chart-select':'foo()'}">
指示:
angular.module('googlechart.directives', ['ui.event']).directive('googleChart', ['$timeout', '$window', function ($timeout, $window) {
return {
restrict: 'A',
scope: {
chart: '=chart'
},
link: function ($scope, $elm, $attr) {
var eventNames="select ready onmouseover animationfinish error onmouseout";
/* ... Set up the chart and chartwrapper. */
google.visualization.events.addListener($scope.chartWrapper, 'ready', function () {
bindChartEvents($scope, eventNames, $scope.chartWrapper.getChart(), $elm);
});
}
};
function bindChartEvents(scope, eventsStr, chart, element) {
angular.forEach(eventsStr.split(' '), function (eventName) {
google.visualization.events.addListener(chart, eventName, function (event) {
var newEventName = 'chart-' + eventName;
element.triggerHandler(newEventName, event);
if (!scope.$$phase){
scope.$apply();
}
});
});
}
}]);