拥有Highcharts指令如何获取/更改当前路径的onClick事件?

时间:2016-11-21 21:56:56

标签: angularjs angularjs-directive highcharts

我有一个带可点击条的高图指令。我想要实现的是onClick来清理查询参数,然后从图表中将新参数添加到URL。但是,当我将$ location注入指令时,onClick事件停止工作 - 我看到路径已更改,但未加载新页面。

以下是代码块:

point:{
  events:{
    click: function (event) {
       location.search({}); // clean up all query parameters
       var path = location.absUrl() + '/sql_id=' + this.category;
       location.href = path; // send me to the new url
    }
  }
}

谢谢!

1 个答案:

答案 0 :(得分:0)

感谢Mitch Lillie,答案是:



atlmonJSDirectives.directive('hcBar', ['$location', function (location) {
  return {
    restrict: 'E',
    scope: {
      items: '=',
      container: '@'
    },
    link: function(scope, element, attrs) {
      scope.$watch('items', function (newval, oldval) {
        if(newval) {
          ...

          var chart = new Highcharts.Chart({
            chart: {
              renderTo: scope.container,
              plotBackgroundColor: null,
              plotBorderWidth: null,
              plotShadow: false,
              height: 270,
              width: 470,
              type: 'bar'
            },
            ...
            series: [{
                data: serValues,
                point:{
                  events:{
                    click: function (event) {
                      location.search({}); // clean up all query parameters
                      var path = location.absUrl() + '/sql_id=' + this.category;
                      window.location.href = path;
                    }
                  }
                }
            }]
          }); 

      }});
    }
  }
}]);