2016-11-21 71 views
1

我有一個可點擊酒吧的highchart指令。我想要實現的是使用onClick清理查詢參數,然後將新的參數從圖表添加到URL。但是,當我將$ location注入到指令中時,onClick事件停止工作 - 我看到路徑已更改,但新頁面未加載。Highcharts指令如何獲取/更改當前路徑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 
    } 
    } 
} 

謝謝!

+0

你能嘗試注入'$ window'和使用'$ window.location'無處不在,你使用'location'? –

+0

它工作,即使我只在一個地方添加窗口。 window.location.href = path; 非常感謝! – Petya

回答

0

感謝米奇利利這裏就是答案:

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; 
 
        } 
 
        } 
 
       } 
 
      }] 
 
      }); 
 

 
     }}); 
 
    } 
 
    } 
 
}]);

相關問題