Reputation: 307
I used AngularJS Filter to search some data. First, set param to search.
<select class="form-control" ng-model="setParam">
<option value="">All</option>
<option value="ptName">Name</option>
<option value="ptCeo">CEO</option>
<option value="ptAddr">Address</option>
<option value="ptTel">Tel</option>
</select>
And then, input search text.
<input type="text" class="form-control" ng-model="ptParam[setParam]">
In this code, ng-model="ptParam[setParam]"
is gonna be filter and used like this.
<div ng-repeat="row in filterData = (partners | filter: setParam ? ptParam : '')">
It works well, but I wanna know how does ng-model="ptParam[setParam]"
work?
Can I get some description?
Upvotes: 0
Views: 29
Reputation: 126
ptParam[setParam] is the way to access to the ptParam’s property named like the actual setParam value. It’s called “bracket notation”. For example:
person['firstname'] = 'Mario';
But in you case you invocked with a variable, with the selected value.
Upvotes: 1