2016-03-08 115 views
0
在C3.js結合

我試圖與點擊條形圖來過濾表中的數據(當我點擊欄上,在表中出現相應的記錄)雙向數據AngularJS

在控制器有從對象中獲取名稱的onlick方法。

onclick: function(d, i) { 
    $scope.country = d.name; 
    console.log($scope.country); 
} 

,還設有隔離範圍的表指令,它的期待國家傳遞

.directive("countryItem", function() { 
    return { 
     restrict: "E", 
     templateUrl: "table.html", 
     //isolated scope and 2-way bind country 
     scope: { 
     country: "=" 
     }, 
     link: function(scope, element, attrs) { 
     scope.countries = [{"country":"Argentina","fifarank":7},{"country":"Belgium","fifarank":12}, {"country":"Croatia","fifarank":14}]; 
     } 
    }; 
    }); 

所以它的指令綁定隔離範圍。

<tr ng-repeat="foot in countries | orderBy:orderByField:reverse | filter:search" country="country"> 

我做錯了什麼?以下是plunker,但onclick方法僅適用於Firefox和較舊版本的Chrome和Opera。

回答

1

夫婦的問題在這裏:

1)在你的Plunker,你是不是在價值傳遞的country的指令 - 應該是這樣的:

<country-item country="country"></country-item> 

2)filter語法錯誤 - 應該是這樣的:

<tr ng-repeat="foot in countries | orderBy:orderByField:reverse | filter:country"> 

3)當你從D3或其他非角事件處理程序調用代碼角度,你需要用它在一個$timeout爲了觸發一個Angular $摘要循環。

onclick: function(d, i) { 
    $timeout(function(){ 
    $scope.country = d.name; 
    console.log($scope.country); 
}); 
} 

Updated Plunker