Skip to content

Commit

Permalink
fix(collectionRepeat): properly display collection repeat inside a modal
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygovier committed Jul 24, 2014
1 parent 4e6ba5b commit 1fbd3c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions js/angular/directive/collectionRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
rerender($scope.$eval(listExpr));
}

// for lists inside a modal, recalc when the modal is shown
$scope.$on('modal.shown',function(){

This comment has been minimized.

Copy link
@ajoslin

ajoslin Jul 24, 2014

Contributor

Wouldn't it be better to have the modal code trigger a resize event on the window?

That way we don't have to couple the modal code with the collectionRepeat code.

This comment has been minimized.

Copy link
@perrygovier

perrygovier Jul 24, 2014

Author Contributor

good point, will refactor

This comment has been minimized.

Copy link
@perrygovier

perrygovier Jul 24, 2014

Author Contributor
onWindowResize();
});

ionic.on('resize', onWindowResize, window);

$scope.$on('$destroy', function() {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/angular/directive/collectionRepeat.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ describe('collectionRepeat directive', function() {
expect(scrollView.resize.callCount).toBe(1);
});

it('should rerender on modal popup', function() {
inject(function($rootScope) {
var el = setup('collection-repeat="item in items" collection-item-height="50"');
var scrollView = el.controller('$ionicScroll').scrollView;
spyOn(scrollView, 'resize');
dataSource.setData.reset();
repeatManager.resize.reset();

el.scope().items = [1, 2, 3];

$rootScope.$broadcast('modal.shown');

expect(dataSource.setData).toHaveBeenCalledWith(el.scope().items);
expect(repeatManager.resize.callCount).toBe(1);
expect(scrollView.resize.callCount).toBe(1);
});
});

it('$destroy', function() {
var el = setup('collection-repeat="item in items" collection-item-height="50"');
dataSource.destroy = jasmine.createSpy('dataSourceDestroy');
Expand Down

0 comments on commit 1fbd3c5

Please sign in to comment.