feat($ionicModal): pass modal instance to modal.shown/modal.hidden events

Fixes #1065
This commit is contained in:
Andy Joslin
2014-04-07 08:04:07 -06:00
parent c6f5ed3b6c
commit a19e3b62f8
2 changed files with 9 additions and 6 deletions

View File

@@ -62,6 +62,9 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
*
* Hint: Be sure to call [remove()](#remove) when you are done with each modal
* to clean it up and avoid memory leaks.
*
* Note: a modal will broadcast 'modal.shown' and 'modal.hidden' events from its originating
* scope, passing in itself as an event argument.
*/
var ModalView = ionic.views.Modal.inherit({
/**
@@ -113,7 +116,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
$timeout(function(){
modalEl.addClass('ng-enter-active');
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown');
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown', self);
self.el.classList.add('active');
}, 20);
@@ -139,7 +142,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
}, 20);
self._isShown = false;
self.scope.$parent && self.scope.$parent.$broadcast('modal.hidden');
self.scope.$parent && self.scope.$parent.$broadcast('modal.hidden', self);
self._deregisterBackButton && self._deregisterBackButton();
ionic.views.Modal.prototype.hide.call(self);

View File

@@ -100,21 +100,21 @@ describe('Ionic Modal', function() {
expect(modalInstance.isShown()).toBe(false);
});
it('should broadcast "modal.shown" on show', function() {
it('should broadcast "modal.shown" on show with self', function() {
var template = '<div class="modal"></div>';
var m = modal.fromTemplate(template, {});
spyOn(m.scope.$parent, '$broadcast');
m.show();
timeout.flush();
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.shown');
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.shown', m);
});
it('should broadcast "modal.hidden" on hide', function() {
it('should broadcast "modal.hidden" on hide with self', function() {
var template = '<div class="modal"></div>';
var m = modal.fromTemplate(template, {});
spyOn(m.scope.$parent, '$broadcast');
m.hide();
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.hidden');
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.hidden', m);
});
it('should broadcast "modal.removed" on remove', inject(function($animate) {