angularjs - 过滤器不适用于`ngmodel`更改
angualrjs - filter not working on `ng-model` changes
我用于对值进行排序的指令过滤器仅适用于页面加载。后来 ng-model
更改不更新集合以及过滤器根本不工作。
如果你觉得我说错了,请指正更新我的演示
谁能帮我解决这个问题?
这是我的代码:
app.directive("customGrid", function($timeout,$filter){
return{
scope:{
"func":"&func",
"pages":"=",
"model":"=ngModel" //not updating?
},
template:temp.join(''),
link : function( scope, element, attrs ){
scope.slice = null;
scope.sortIt = function( value ){
console.log( value )
scope.slice = $filter('orderBy')(value, '', true);//works on load
$timeout(function(){
scope.$apply();
})
}
$timeout(function(){
scope.slice = scope.pages.pin;
scope.sortIt( scope.slice );
})
}
}
})
我已经更新了模糊排序列表的示例,问题出在输入框的模型上,我们需要更新列表才能进行排序。
您还需要添加 type = "number"
否则您每次都必须在指令控制器中转换为数字。
var temp = [
"<ul><li ng-repeat='(key,value) in slice track by $index'>",
"<input ng-model=slice[key] type='number' ng-blur=sortIt(slice) /></li></ul>"
]
我用于对值进行排序的指令过滤器仅适用于页面加载。后来 ng-model
更改不更新集合以及过滤器根本不工作。
如果你觉得我说错了,请指正更新我的演示
谁能帮我解决这个问题?
这是我的代码:
app.directive("customGrid", function($timeout,$filter){
return{
scope:{
"func":"&func",
"pages":"=",
"model":"=ngModel" //not updating?
},
template:temp.join(''),
link : function( scope, element, attrs ){
scope.slice = null;
scope.sortIt = function( value ){
console.log( value )
scope.slice = $filter('orderBy')(value, '', true);//works on load
$timeout(function(){
scope.$apply();
})
}
$timeout(function(){
scope.slice = scope.pages.pin;
scope.sortIt( scope.slice );
})
}
}
})
我已经更新了模糊排序列表的示例,问题出在输入框的模型上,我们需要更新列表才能进行排序。
您还需要添加 type = "number"
否则您每次都必须在指令控制器中转换为数字。
var temp = [
"<ul><li ng-repeat='(key,value) in slice track by $index'>",
"<input ng-model=slice[key] type='number' ng-blur=sortIt(slice) /></li></ul>"
]