zzangs33
zzangs33

Reputation: 307

How does this AngularJS Filter work? Give me some description

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

Answers (1)

alandria
alandria

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

Related Questions