What I am trying to do is to make a search function. I want to have multiple options by using checkboxes and depending on the value of each checkbox to call a function in the controller. In details what I have done until now is a dropdown menu:
<input type="text" placeholder="Search Keyword..." ng-model="searchKeyword">
<select ng-model="selectedProperty">
<option value="usersUsername">Users: Username</option>
<option value="accountsName">Accounts: Name</option>
</select>
<button type="submit" ng-click="search()">Search</button>
and in the controller I am checking which property has been selected and I am calling the corresponding function
$scope.search = function () {
switch ($scope.selectedProperty) {
case 'usersUsername':
searchByUsersUsername($scope.searchKeyword)
break;
case 'accountsName':
searchByAccountsName($scope.searchKeyword)
break;
}
};
So what I am trying now is to change the dropdown menu to multiple selected checkboxes and if for example both users-usernames and accounts-name are selected to call the function in the controller searchByUsersUsernameAccountsName($scope.searchKeyword).
You can show the check boxes through an array of objects from the controller scope with an attribute bounding to the checkbox value. And inside the search function you check for that attribute value for each object that is bound to check boxes.
Here is the code example I have in mind.
In controller
Now in your HTML file, render those check boxes through ng-repeat
Now in your search function in controller
and in the
searchFn
, you can just append thisurlParams
string after the question mark in the url.