2016-11-21 6 views
1

私はクリック可能なバーを持つハイチャート指示文を持っています。私が達成したいのは、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

試すことはできますか? –

+0

ウィンドウを1か所に追加しても機能しました。 window.location.href = path; ありがとう! – Petya

答えて

0

おかげで答えている:あなたは `$のwindow`を注入し、どこでもあなたが` location`を使用し、 `$のwindow.location`を使用して

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

 
     }}); 
 
    } 
 
    } 
 
}]);

関連する問題