Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 7910536

Browse files
fix(modal): allow in-lined controller-as controllers
1 parent 8d7c2a2 commit 7910536

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/modal/modal.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
354354
modalScope.$close = modalInstance.close;
355355
modalScope.$dismiss = modalInstance.dismiss;
356356

357-
var ctrlLocals = {};
357+
var ctrlInstance, ctrlLocals = {};
358358
var resolveIter = 1;
359359

360360
//controllers
@@ -365,7 +365,10 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
365365
ctrlLocals[key] = tplAndVars[resolveIter++];
366366
});
367367

368-
$controller(modalOptions.controllerAs ? modalOptions.controller + ' as ' + modalOptions.controllerAs : modalOptions.controller, ctrlLocals);
368+
ctrlInstance = $controller(modalOptions.controller, ctrlLocals);
369+
if (modalOptions.controller) {
370+
modalScope[modalOptions.controllerAs] = ctrlInstance;
371+
}
369372
}
370373

371374
$modalStack.open(modalInstance, {

src/modal/test/modal.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ describe('$modal', function () {
313313
open({template: '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>', controller: 'TestCtrl', controllerAs: 'test'});
314314
expect($document).toHaveModalOpenWithContent('Content from ctrl true', 'div');
315315
});
316+
317+
it('should allow defining in-place controller-as controllers', function () {
318+
open({template: '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>', controller: function($modalInstance) {
319+
this.fromCtrl = 'Content from ctrl';
320+
this.isModalInstance = angular.isObject($modalInstance) && angular.isFunction($modalInstance.close);
321+
}, controllerAs: 'test'});
322+
expect($document).toHaveModalOpenWithContent('Content from ctrl true', 'div');
323+
});
316324
});
317325

318326
describe('resolve', function () {

0 commit comments

Comments
 (0)