0

So, here is a link to the code http://plnkr.co/edit/Rrn6EA0nidatGWjMlwkw?p=preview

Problem Since I am using an ion-infinite-scroll directive and a for loop to dynamically fill the feed tab with content I can't get the search input to work, however when I was using the data.json file statically calling it once and getting everything the search input was working. I have guesses why it is not working but they are not really helping me

here is the code in case it catches someone's eye HTML

<div class="bar bar-subheader 
  item-input-inset bar-light">
  <label class="item-input-wrapper">
    <i class="icon ion-search placeholder-icon"></i>
    <input type="search" ng-model="query" placeholder="Search for post">
  </label>
</div>
<ion-content class="has-subheader">
    <ion-refresher on-refresh="load()">
    </ion-refresher>
    <ion-list>
        <ion-item ng-repeat='post in posts track by post.id | filter: query ' class='item-thumbnail-left item-text-wrap' href="#/tab/list/{{post.id}}">
            <img ng-src='{{post.photo}}' />
            <div>
            <p class='shortText titleArticle'>
                {{post.title | limitTo: 33}}
                {{ post.title.length > 33 ? '&hellip;' : '' }}
            </p>    
            <img class='articleAuthImg' src="http://cliparts.co/cliparts/kT8/oja/kT8oja7xc.png" alt="StoyanGenchev-author" />    
            </div>
            <div class='articleInfo'>
            <h2>{{post.author}}</h2>
            <h4>{{post.date}}</h4>
            <h4 class="category">{{post.category}}</h4>
            </div>
            <div class="clear"></div>
            <p class='shortText'>
                {{post.description | limitTo: 200}}
                {{ post.description.length > 200 ? '&hellip;' : '' }}
            </p>
        </ion-item>
    </ion-list> 
    <ion-infinite-scroll
    ng-if="noMore()"    
    on-infinite="get_more()"
    distance="15%"
    >
  </ion-infinite-scroll>
</ion-content>

APP.JS

starter.controller('ListController', ['$scope', '$http', '$stateParams',
function($scope, $http, $stateParams) {

$scope.posts = [];  
var startingPoint = 0;
var limit = 1;

$scope.load=function(startingPoint, limit){

$http.get('data.json').success(function(data) {

  for(var i = startingPoint; i<=limit; i+=1){
      $scope.posts.push(data.posts[i]);
      $scope.id=$stateParams.id;
  }

})
 .finally(function(){
                $scope.$broadcast('scroll.refreshComplete');
                $scope.$broadcast('scroll.infiniteScrollComplete');
            });

};

$scope.get_more = function(){
            $scope.load(startingPoint, limit);
            limit+=2;
            startingPoint+=2;
        };   

$scope.noMore = function(){
    return ($scope.posts.length > 50) ? false : true;
};

  }]);

ANY HELP WILL BE APPRECIATED

2
  • Your code seems to work. E.g. just change one title in data.json and you will be able to apply the filter for it. Your filtering is not happening because you're having identical data in data.json so the filter query will allways match all items. Commented Aug 3, 2015 at 21:42
  • No, it is not that. Did your really try it? I can filter by id or category too and that way I can see whether it is working or not and right now, nothing is happening and I don't know where to look for guidance Commented Aug 4, 2015 at 8:12

1 Answer 1

1

I think the track by post.id is the problem here.

It should be like this: <ion-item ng-repeat='post in posts | filter: query track by post.id' >

track by should be added after filtering. See also this SO question.

Yesterday I probably just removed the track by because I wasn't aware that the order matters here.

Updated plunker. Search for tech works to see the filtering.

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

Comments

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.