On Saturday, June 25, 2016 at 9:08:30 PM UTC+2, Shiva Rowshan rad wrote:
>
> Hi everyone
> I have a Json Data which I showed in rows with 2 columns. I put a search
> box to show the search results by filter . but it does not work correctly .
> Sometimes it shows both data and its next index , sometimes it shows the
> data in both columns of a row and sometimes it shows nothing at all.
> How should I make it correct ?
>
>
>
So two things to note here:
1. I don't know what your problem exactly is - perhaps you're matching
stuff from "book.type", "book.author" or whatever else property, not just
name.
If you want to limit the search, just limit it to your name property
directly:
<input ng-model="search.name"></label><br>
<tr ng-repeat="item in items | filter:search">
{{ item.name }} - {{ item.type }}
</tr>
2. Layout - you have a weird thing there with ng-if:
ng-if="$index%2==0"
That would limit you to only show every second row of the array (filtered
or full, regardless). Why is that? Are you trying to lay the data out in
two columns?
Why not simply use some simple grid?
Like:
<div class="results grid">
<div class="col-1-2" ng-repeat="item in items">
<span>{{ item.name }}, {{ item.type }}</span>
</div>
</div>
See this plunkr: http://plnkr.co/edit/7jDQfD3OA9QkP1aYoM0L
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.