diff --git a/src/modal/docs/readme.md b/src/modal/docs/readme.md index 1c36320f00..89b115b109 100644 --- a/src/modal/docs/readme.md +++ b/src/modal/docs/readme.md @@ -6,7 +6,8 @@ The `$modal` service has only one method: `open(options)` where available option * `templateUrl` - a path to a template representing modal's content * `template` - inline template representing the modal's content * `scope` - a scope instance to be used for the modal's content (actually the `$modal` service is going to create a child scope of a provided scope). Defaults to `$rootScope` -* `controller` - a controller for a modal instance - it can initialize scope used by modal. Accepts the "controller-as" syntax, and can be injected with `$modalInstance` +* `controller` - a controller for a modal instance - it can initialize scope used by modal. Accepts the "controller-as" syntax in the form 'SomeCtrl as myctrl'; can be injected with `$modalInstance` +* `controllerAs` - an alternative to the controller-as syntax, matching the API of directive definitions. Requires the `controller` option to be provided as well * `resolve` - members that will be resolved and passed to the controller as locals; it is equivalent of the `resolve` property for AngularJS routes * `backdrop` - controls presence of a backdrop. Allowed values: true (default), false (no backdrop), `'static'` - backdrop is present but modal window is not closed when clicking outside of the modal window. * `keyboard` - indicates whether the dialog should be closable by hitting the ESC key, defaults to true @@ -27,4 +28,4 @@ In addition the scope associated with modal's content is augmented with 2 method * `$close(result)` * `$dismiss(reason)` -Those methods make it easy to close a modal window without a need to create a dedicated controller +Those methods make it easy to close a modal window without a need to create a dedicated controller. diff --git a/src/modal/modal.js b/src/modal/modal.js index 043596484c..d17377b826 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -365,7 +365,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) ctrlLocals[key] = tplAndVars[resolveIter++]; }); - $controller(modalOptions.controller, ctrlLocals); + $controller(modalOptions.controllerAs ? modalOptions.controller + ' as ' + modalOptions.controllerAs : modalOptions.controller, ctrlLocals); } $modalStack.open(modalInstance, { diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 153b531d0a..3a9d33c1f4 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -1,5 +1,5 @@ describe('$modal', function () { - var $rootScope, $document, $compile, $templateCache, $timeout, $q; + var $controllerProvider, $rootScope, $document, $compile, $templateCache, $timeout, $q; var $modal, $modalProvider; var triggerKeyDown = function (element, keyCode) { @@ -290,7 +290,7 @@ describe('$modal', function () { $scope.isModalInstance = angular.isObject($modalInstance) && angular.isFunction($modalInstance.close); }; - var modal = open({template: '