[英]Is it possible to pass HTML input field variables to a custom Angularjs filter?
I'm new to Angular so this might be real easy. 我是Angular的新手,所以这可能真的很容易。 I have a JSON array of some offers.
我有一些商品的JSON数组。 Each offer has a price among other things.
每个报价都有一个价格。 I want to be able to add a filter so that the user can specify their min/max spent and only sees offers that fall into these brackets.
我希望能够添加一个过滤器,以便用户可以指定花费的最低/最高费用,并且只能看到属于这些括号的商品。
In the list controller I have 在列表控制器中,我有
// MinMax filter:
$scope.minMax = function(prop, mn, mx){
return function(item){
if ( (Number(item[prop]) >= mn) && (Number(item[prop])<= mx) ) return true;
}
}
In the View HTML I have two simple text input fields: 在View HTML中,我有两个简单的文本输入字段:
<input id='cheapest' name="cheapest" type='text' value='10' />
<input id='dearest' name="dearest" type='text' value='5000' />
and the repeater 和中继器
<div ng-repeat="offer in offers | filter: minMax('Price' , [?cheapest?], [?dearest?]) ">
The filter works when I hardcode values in, but how do I bind them to the input field? 当我对值进行硬编码时,过滤器可以工作,但是如何将它们绑定到输入字段?
Thanks 谢谢
This is a calling to Captain ngModel
;) 这是对
ngModel
上尉的ngModel
;)
Just bind your input
values: 只需绑定您的
input
值:
<input id='cheapest' name="cheapest" type='text' value='10' ng-model="cheapest" />
<input id='dearest' name="dearest" type='text' value='5000' ng-model="dearest" />
and pass the value to your filter: 并将值传递给您的过滤器:
<div ng-repeat="offer in offers | filter: minMax('Price', cheapest, dearest) ">
or access them via $scope.cheapest
in your controller . 或通过控制器中的
$scope.cheapest
访问它们。
I am not sure with the syntax though but it will work somehow :) 虽然我不确定语法,但是它会以某种方式起作用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.