Skip to content Skip to sidebar Skip to footer

Angular: Watch For Filtered Value In Directive

I'm trying to implement a directive that draws a chart based on given values. I want the pass the data for the plot from the template. I have a working solution, passing the data i

Solution 1:

What about saving the filtered list in a different variable in your controller? something like:

$scope.filteredList = $filter('yourFilter')($scope.list);

and in the HTML:

<chart ????="filteredList" />

You only need to make sure you update filteredList whenever list changes.

Solution 2:

What about actually placing binding on the ???? variable:

<chart ???????="{{list | filter}}" />

You might also want to add in your directive:

return{
    restrict: 'C',
    scope: {
        ????: "@",
    },
    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();
            }
        });
    }
};

Post a Comment for "Angular: Watch For Filtered Value In Directive"