I have these two views:
1) foo.html
Hello {{name}}
2) foo-as-modal.html
Well I solved this way:
$uibModalInstance
from fooController
When invoking the modal, I pass the modalInstance as a variable to the modal's scope:
var modalScope = $scope.$new();
var modalInstance = $uibModal.open({
templateUrl: 'foo-as-modal.html',
controller: 'fooController',
scope: modalScope
});
modalScope.modalInstance = modalInstance;
Dismiss the modal with the scope variable:
$scope.modalInstance.dismiss('cancel'); // instead of $uibModalInstance.dismiss(..)
Here is a fork of the original plunkr, with this solution: https://plnkr.co/edit/ZasHQhl6M5cCc9yaZTd5
One way to do this is to resolve $uibModalInstance
in the route with null (or an empty string/or whatever you please) and inject it into the controller. If the html page isn't opened as a modal, you still have $uibModalInstance
. If it's opened as a modal, $uibModalInstance
is automatically injected.
You can not use the same controller for a page view and for a modal window. At least, untill controller depends on $uibModalInstance
.
$uibModalInstance
can be injected only in modals.