0

I am using Angular to filter an array of data for a table. The filter works on the table but when I select one of the select options it inserts [object Object] into my text input. How do I stop this?

<div class='table-filters'>

  <div class='row'>
    <label>Search</label>
    <input ng-model="query"   name='search' >
  </div>

  <div class='row'>
    <label for='category'>Category</label>
    <select ng-model="query.cat">
      <option value="">Any</option>
      <option value="VOWEL">Vowels</option>
      <option value="CONSONANT">Consonants</option>
      <option value="NUMBER">Digits</option>
      <option value="SIGN: DEP">Dependent Signs</option>
      <option value="SIGN: IND">Independent Signs</option>
    </select>
  </div>

  <div class='row'>
    <label for='matched-rows'>Matched Characters</label>
    <span id='matched-rows'>{{(rows|filter:query).length}}</span<
  </div>

</div>

2 Answers 2

2

I seem to have found a solution form this plunker http://plnkr.co/edit/XklvXtc1AZpndjLvXrh8?p=preview;

<div class='row'>
 <label>Search</label>
 <input ng-model="query[queryBy]"   name='search' >
</div>

js file:

demo.controller('demoController', function($scope){

    $scope.rows = getRows();
    $scope.query = {};
    $scope.queryBy = '$';

});

I should have put my js file in the question, I know. Apologies for the poorly written question. Thank you.

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

Comments

0

query is Object and its toString() implementation returns [object Object].

Use query.cat as ng-model for input.

<input ng-model="query.cat"   name='search' >

2 Comments

but won't that restrict the search to just .cat property. I won't to be able to filter the array against all properties not just the .cat.
But in that case you don't need input. Just use your query object and do filtering. From what I see you will have to define custom filtering method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.