Hi all, I’m new to Ionic/Cordova/Angular etc so I’m hoping someone with more experience can quickly point out what I’m doing wrong.
I’ve created a conference type app using the ionic tab template. On one of my tabs I display a list of conference attendees. I would like to be able to search the list and display the results that match the search input text.
The code I have is currently working on my iPhone emulator(s) and is also working fine when I run the app in a browser. However, if I push the app to my physical iOS device my app is crashing occasionally when I type in the input field.
Here are my code snippets.
1. My ion-view
<ion-list>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="attendee in attendees" type="item-text-wrap" href="#/tab/attendees/{{attendee.id}}">
<img ng-src="{{attendee.face}}">
<h2>{{attendee.name}}</h2>
<p>{{attendee.title}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
</ion-list>
</ion-content>
2. My Controller
.controller(‘AttendeesCtrl’, function($scope, Attendees) {
$scope.attendees = Attendees.all();
$scope.search = function(searchString){
if(searchString == null || searchString == “”){
$scope.attendees = Attendees.all();
}
else{
//$scope.attendees = [];
var tempList = [];
var attendeeList = Attendees.all();
var len = attendeeList.length;
var item;
for (var i=0; i<len; i++) {
item = attendeeList[i];
if (item.name.toLowerCase().indexOf(searchString.toLowerCase()) > -1) {
tempList.push(item);
}
}
$scope.attendees = tempList;
}
}
})
Thanks for any possible help in advance!
Chris