Skip to content

Instantly share code, notes, and snippets.

@onigetoc
Last active February 21, 2016 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onigetoc/56b0d8fe736c0db72758 to your computer and use it in GitHub Desktop.
Save onigetoc/56b0d8fe736c0db72758 to your computer and use it in GitHub Desktop.
Angular Google Contact phone number filter
/*** PHONE FILTER ***/
// .controller('ContactsCtrl', function ($scope, $filter)
.filter('PhoneFilter', function () {
return function (input, search) {
if (!search) {
return input;
}
var result = [];
search = search.replace(/[+()-\s]/g, "").toLowerCase();
angular.forEach(input, function (item) {
if (item.hasOwnProperty('gd$phoneNumber')) {
if (item.title.$t.replace(/[-\s]/g, "").toLowerCase().indexOf(search) !== -1 || item.gd$phoneNumber[0]['$t'].replace(/[+()-\s]/g, "").toLowerCase().indexOf(search) !== -1) {
result.push(item);
}
}
});
return result;
};
});
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" placeholder="Search Contacts" ng-model="search" ng-minlength="2" style="width:100%; padding-left:11px;">
<a ng-if="search.length" on-touch="search=''">
<i class="icon ion-close placeholder-icon"></i>
</a>
</label>
<ion-list>
<ion-item class="item-avatar item-icon-right" ng-if="item.gd$phoneNumber[0]['$t']" ng-repeat="item in items | PhoneFilter:search:search | orderBy:'title.$t'" ng-click="showActionsheet({{ item }})">
<img ng-if="item.link[0]['gd$etag']" data-src="{{item.link[0]['href']}}&access_token={{token}}">
<img ng-if="!item.link[0]['gd$etag']" ng-src="{{placeholder}}">
<h2 ng-if="item.title.$t">{{ item.title.$t }}</h2>
<p ng-if="item.gd$phoneNumber[0]['$t']"> <i class="ion-android-call"></i> {{ item.gd$phoneNumber[0]['$t'] }}
<p/>
<p ng-if="item.gd$email[0]['address']"> <i class="ion-android-mail"></i> {{ item.gd$email[0]['address'] }}
<p/>
<!-- icon-accessory-->
<i class="icon ion-ios-star-outline energized"></i>
<ion-option-button class="button-assertive" ng-click="remove(chat)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment