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

Commit

Permalink
fix(modal): allow in-lined controller-as controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
pkozlowski-opensource committed May 27, 2014
1 parent 8d7c2a2 commit 7910536
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/modal/modal.js
Expand Up @@ -354,7 +354,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
modalScope.$close = modalInstance.close;
modalScope.$dismiss = modalInstance.dismiss;

var ctrlLocals = {};
var ctrlInstance, ctrlLocals = {};
var resolveIter = 1;

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

$controller(modalOptions.controllerAs ? modalOptions.controller + ' as ' + modalOptions.controllerAs : modalOptions.controller, ctrlLocals);
ctrlInstance = $controller(modalOptions.controller, ctrlLocals);
if (modalOptions.controller) {
modalScope[modalOptions.controllerAs] = ctrlInstance;
}
}

$modalStack.open(modalInstance, {
Expand Down
8 changes: 8 additions & 0 deletions src/modal/test/modal.spec.js
Expand Up @@ -313,6 +313,14 @@ describe('$modal', function () {
open({template: '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>', controller: 'TestCtrl', controllerAs: 'test'});
expect($document).toHaveModalOpenWithContent('Content from ctrl true', 'div');
});

it('should allow defining in-place controller-as controllers', function () {
open({template: '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>', controller: function($modalInstance) {
this.fromCtrl = 'Content from ctrl';
this.isModalInstance = angular.isObject($modalInstance) && angular.isFunction($modalInstance.close);
}, controllerAs: 'test'});
expect($document).toHaveModalOpenWithContent('Content from ctrl true', 'div');
});
});

describe('resolve', function () {
Expand Down

0 comments on commit 7910536

Please sign in to comment.