javascript - angular: watch for filtered value in directive -
i'm trying implement directive draws chart based on given values. want pass info plot template. have working solution, passing info in ng-model, can add together $scope.watch statement. doesn't work filtered data, , don't need two-way binding.
ideally, html should like:
<chart ???????="list | filter" /> the directive, guess, should like:
return{ restrict: 'c', link: function(scope, elem, attrs){ var chart = null scope.$watch(????, function(v){ if(!chart){ chart = $.plot(elem, v , options); elem.show(); }else{ chart.setdata(v); chart.setupgrid(); chart.draw(); } }); } }; is there angular way accomplish this?
what saving filtered list in different variable in controller? like:
$scope.filteredlist = $filter('yourfilter')($scope.list); and in html:
<chart ????="filteredlist" /> you need create sure update filteredlist whenever list changes.
javascript angularjs angularjs-directive angularjs-scope angularjs-filter
No comments:
Post a Comment