0

I'm trying to filter data in table with click on the bar chart (when I click on the bar, in the table appears corresponding record)

In the controller there is onlick method for getting the name from the object.

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

There is also a table directive with isolated scope and it's expecting a country to be passed

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

so it's binded in directives isolate scope.

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

What I'm doing wrong? Here is the plunker, but onclick method works only on Firefox and older version of Chrome and Opera.

1 Answer 1

1

Couple of issues here:

1) In your Plunker, you were not passing in a value for country to the directive - should be like this:

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

2) Syntax error on filter - should be like this:

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

3) When you call Angular code from a D3 or other non-Angular event handler, you need to wrap it in a $timeout in order to trigger an Angular $digest cycle.

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

Updated Plunker

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.