Vitaly Menchikovsky
Vitaly Menchikovsky

Reputation: 8884

filter not working on ng-repeat

I have an array of contacts, my objects looks like:

{"active":false,"lastName":"fdg","name":"riman","table":3}....

I can see all items but the filter just not working, my template is :

    <ion-header-bar class="bar-subheader item-input-inset">
    <label class="item-input-wrapper">
        <i class="icon ion-ios7-search placeholder-icon"></i>
        <input type="search" placeholder="Search" ng-model="searchText">
    </label>
    <button class="button button-clear" ng-click="searchText =''">
        Cancel
    </button>
</ion-header-bar>
<ion-content>
    <ul class="list  item-icon-right">
        <li class="item row" ng-repeat="(tel, contact) in contacts | filter:searchText">

update:

my code is for firebase:

   $scope.contacts = {};
        $scope.data = $firebaseObject(ref);
        $scope.data.$loaded()
            .then(function () {
                $scope.contacts = $scope.data.contacts;
            })

Upvotes: 1

Views: 2123

Answers (4)

Vitaly Menchikovsky
Vitaly Menchikovsky

Reputation: 8884

fix the issue. ng repeat will work but ng filter cant filter object that have an array, it should be an array of objects.

Upvotes: 0

jsmtslch
jsmtslch

Reputation: 718

Check out this plunkr if it helps

Plunkr for filter
I have added something like:
<li class="item row" ng-repeat="(tel, contact) in contacts | filter:searchText"> {{contact.lastName}} </li>

Upvotes: 1

tanenbring
tanenbring

Reputation: 780

Wrap the searchText variable in an object:

$scope.search = {text: ""};

Then reference that instead. Primitives don't propagate along the scope.

Upvotes: 0

aseferov
aseferov

Reputation: 6393

if you are filter for object you need specify property

 <li class="item row" ng-repeat="(tel, contact) in contacts | filter: {name: searchText}">

and you can add more fields for filter

ng-repeat="(tel, contact) in contacts | filter: {name: searchText, lastName:  searchText}"

Upvotes: 0

Related Questions