Skip to content

Commit a19e3b6

Browse files
committed
feat($ionicModal): pass modal instance to modal.shown/modal.hidden events
Fixes #1065
1 parent c6f5ed3 commit a19e3b6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Diff for: js/ext/angular/src/service/ionicModal.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
6262
*
6363
* Hint: Be sure to call [remove()](#remove) when you are done with each modal
6464
* to clean it up and avoid memory leaks.
65+
*
66+
* Note: a modal will broadcast 'modal.shown' and 'modal.hidden' events from its originating
67+
* scope, passing in itself as an event argument.
6568
*/
6669
var ModalView = ionic.views.Modal.inherit({
6770
/**
@@ -113,7 +116,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
113116

114117
$timeout(function(){
115118
modalEl.addClass('ng-enter-active');
116-
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown');
119+
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown', self);
117120
self.el.classList.add('active');
118121
}, 20);
119122

@@ -139,7 +142,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
139142
}, 20);
140143

141144
self._isShown = false;
142-
self.scope.$parent && self.scope.$parent.$broadcast('modal.hidden');
145+
self.scope.$parent && self.scope.$parent.$broadcast('modal.hidden', self);
143146
self._deregisterBackButton && self._deregisterBackButton();
144147

145148
ionic.views.Modal.prototype.hide.call(self);

Diff for: js/ext/angular/test/service/ionicModal.unit.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,21 @@ describe('Ionic Modal', function() {
100100
expect(modalInstance.isShown()).toBe(false);
101101
});
102102

103-
it('should broadcast "modal.shown" on show', function() {
103+
it('should broadcast "modal.shown" on show with self', function() {
104104
var template = '<div class="modal"></div>';
105105
var m = modal.fromTemplate(template, {});
106106
spyOn(m.scope.$parent, '$broadcast');
107107
m.show();
108108
timeout.flush();
109-
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.shown');
109+
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.shown', m);
110110
});
111111

112-
it('should broadcast "modal.hidden" on hide', function() {
112+
it('should broadcast "modal.hidden" on hide with self', function() {
113113
var template = '<div class="modal"></div>';
114114
var m = modal.fromTemplate(template, {});
115115
spyOn(m.scope.$parent, '$broadcast');
116116
m.hide();
117-
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.hidden');
117+
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.hidden', m);
118118
});
119119

120120
it('should broadcast "modal.removed" on remove', inject(function($animate) {

0 commit comments

Comments
 (0)