I am displaying all of the articles from the database and I've created a simple text search for it.
<input ng-model="searchText" placeholder="Search for articles" class="search-text">
And I am filtering the content from the searchText
<section class="articles" ng-repeat="contentItem in content | filter:searchText">
Now what I'm trying is to have buttons with the categories and tags from my database and to be able to filter the content based on the button values.
<span ng-repeat="category in categories">
  <button ng-click="searchText = '{{category.local.name}}'" class="btn btn-primary">{{ category.local.name }}</button>
</span>
The code above is not working but for example if I'm taking out the ng-repeat and type all the categories myself it will work:
<span>
  <button ng-click="searchText = 'some text'" class="btn btn-primary">Some text</button>
</span>
My question is how can be the good way to pass the content from the search input and buttons to the filter method?
Here is the full code:
<div class="container">
 <h1>List of articles</h1>
<section class="search-items">
<input ng-model="searchText" placeholder="Search for articles" class="search-text">
<div class="row">
  <div class="col-sm-6">
    <h6>Search based on categories:</h6>
    <span ng-repeat="category in categories">
      <input type="button" ng-click="searchText = '{{ category.local.name }}'" value="{{ category.local.name }}" class="btn btn-primary">
    </span>
  </div>
  <div class="col-sm-6">
    <h6>Search based on tags:</h6>
    <span ng-repeat="tag in tags">
      <input type="button" ng-click="searchText = '{{tag.local.name}}'" value="{{ tag.local.name }}" class="btn btn-primary">
    </span>
  </div>
</div>
</section>
<section class="articles" ng-repeat="contentItem in content | filter:searchText">
  <article class="well">
    <h3>{{ contentItem.local.title }}</h3>
    <p>{{ contentItem.local.content }}</p>
    <span><b>Article author: {{ contentItem.local.author }}</b></span><br/>
    <span class="label label-primary">{{ contentItem.local.categories.category }}</span>
    <span class="label label-primary">{{ contentItem.local.tags.tag }}</span>
  </article>
 </section>
</div>
 
     
     
    
{{searchText|json}}` in the view you should see that searchText gets updated with the value of tag.local.name as parsed against the scope for the repeated element. I'll try to make a minimal sample answer. – shaunhusain May 25 '16 at 01:47