Hi Folks,
My app is a company directory that uses Collection-Repeat to create roughly 200 list items. Each list item has a ng-click to open a Modal. This worked great when I was using ng-repeat, but now it is creating a strange behavior…
The phone displays roughly 5 list items on the viewport. If I were to click on the top list item to open the modal, it instead opens a modal for the bottom list item (bottom of the viewport, so item #5). When I click on item #2, it opens a modal for item #4, when I click #3 the modal doesn’t open. I’m not getting any errors in the console so it has me scratching my head.
Any ideas? Here is my code:
<ion-content>
<div class="list">
<a class="item my-item"
collection-repeat="row in contacts"
collection-item-height="getItemHeight(row)"
collection-item-width="'100%'"
ng-class="{'item-divider': row.isLetter}">
<img ng-controller="ModalCtrl" ng-click="modal.show()" ng-if="!row.isLetter" ng-src="data:image/jpeg;base64,{{row.image}}">
<h2>{{row.title || (row.firstname+' '+row.lastname)}}</h2>
<p ng-if="!row.isLetter"><em>{{row.jobtitle}}</em></p>
</a>
</div>
</ion-content>
Here is the controller code:
app.controller('IntroCtrl', function($scope, $ionicScrollDelegate, $ionicSideMenuDelegate) {
var contacts = $scope.contacts = [];
var currentDepartment = '';
var dep_listing = angular.fromJson(window.localStorage['data']);
dep_listing.sort(function(a, b) {
return a.department > b.department ? 1 : -1;
})
.forEach(function(dep) {
if(currentDepartment != dep.department) {
contacts.push({
isLetter: true,
title: dep.department
});
currentDepartment = dep.department;
}
contacts.push(dep);
});
$scope.getItemHeight = function(row) {
return row.isLetter ? 40 : 77;
};
};
});
Here is the modal template:
<header class="bar bar-header bar-lsi">
<h1 class="title">Contact Information</h1>
<div class="button button-clear" ng-click="closeModal()"><span class="icon ion-close"></span></div>
</header>
<ion-content has-header="true" style="margin-top: 0px !important;">
<div class="list card" style="border-radius: 0px !important;">
<div class="item item-avatar item-text-wrap">
<img ng-src="data:image/jpeg;base64,{{row.image}}">
<h2>{{row.firstname}} {{row.lastname}}</h2>
<p>{{row.jobtitle}}</p>
</div>
<a href="tel:{{row.phone}}" class="item item-icon-left">
<i class="icon ion-iphone"></i>
{{row.phone}}
</a>
<a href="mailto:{{row.email}}" class="item item-icon-left">
<i class="icon ion-email"></i>
{{row.email}}
</a>
</div>
<button class="button button-block button-lsi" ng-click="closeModal()">Close Popup</button>
</ion-content>
And then of course the basic Modal Controller:
app.controller('ModalCtrl', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
});