mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat($ionicModal): pass modal instance to modal.shown/modal.hidden events
Fixes #1065
This commit is contained in:
7
js/ext/angular/src/service/ionicModal.js
vendored
7
js/ext/angular/src/service/ionicModal.js
vendored
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user