角度:手表在指令中值滤波 [英] angular: watch for filtered value in directive
问题描述
我想实现绘制根据给定值的图表指令。
我想通过数据从模板中的情节。
我有一个工作的解决方案,传递数据 NG-模型
,为此我可以再增加一个 $ scope.watch
语句。但是,这并不与过滤数据的工作,而且我也不需要双向绑定。
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 in ng-model
, for which I can then add a $scope.watch
statement. But that doesn't work with filtered data, and I don't need two-way binding.
理想情况下,HTML应该是这样的:
Ideally, the html should look like:
<chart ???????="list | filter" />
该指令,我想,应该是这样的:
The directive, I guess, should look 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 an angular way to achieve this?
推荐答案
有关在你的控制器保存在一个不同的变量过滤列表是什么?
是这样的:
What about saving the filtered list in a different variable in your controller? something like:
$scope.filteredList = $filter('yourFilter')($scope.list);
和在HTML
<chart ????="filteredList" />
您只需要确保您更新 filteredList
每当列表
的变化。
You only need to make sure you update filteredList
whenever list
changes.
这篇关于角度:手表在指令中值滤波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!