1

I am using AngularJS and AngularUI Bootstrap's Typeahead. I want to use the filter with multiple parameters. Here is my input control:

<input id="tbUsers" class="form-control" ng-model="unit.userSel"
                                typeahead="user as user._FName + '(' +  user._LName +')' for user in allUsers | filter:{_FName : _LName:$viewValue}:myFunc | limitTo:8"                                    
                                typeahead-editable="false" required />

In my controller I have function for myFunc:

$scope.myFunc = function (FName, LName, viewValue) {
    //logic here
    return true;
}

I am unable to pass multiple parameters to myFunc. If I remove the LName param from controller function and the input filter, then it works fine. If I add 2 parameters, myFunc doesn't get called.

Please help!!
P.S.: My first question here, so I might have broken a few rules, sorry about that!

1 Answer 1

2

So there are many solutions to the problem you face. If you want the "proper answer", the filter is done through Angular's filter module so you should take a look at the following: https://docs.angularjs.org/api/ng/filter/filter (one easy way to do it would just be to combine two parameters in an ng-model)

If you want a really easy answer... You could just pass it the object instead of a property of an object, that way it filters on everything.

Sign up to request clarification or add additional context in comments.

2 Comments

Well true about that, but then I need to filter only on 2 fields, and that object is huge, with more than 10 fields. Angular's filter module looks like a feasible way for now.
The filter in UI bootstrap is based off filter (so you can essentially do the same stuff...)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.