I have recently had to solve the same issue. Finally this has worked.
Originally, my code looked like this:
app.controller('PaymentController', ['$injector', 'PaymentService',
'$scope', '$rootScope', '$uibModalInstance', PaymentConstructor]);
function PaymentConstructor($injector, PaymentService, $scope, $rootScope, $modalInstance) {
$scope.view = '';
...and so on...
..and requirement was to conditionally have/or not have the $uibModalInstance
in the controller function.
Use this instead:
app.controller('PaymentController', dependencyInjection);
where dependencyInjection
is array variable declared above:
var dependencyInjection = ['$injector', 'PaymentService', '$scope', '$rootScope']
..now you can decide - what to put to the array or what to not put. e.g.:
if (includeUibInstance) dependencyInjection.push('$uibModalInstance');
if (includeUibInstance) {
dependencyInjection.push(PaymentConstructorWithUib);
} else {
dependencyInjection.push(PaymentConstructorNoUib);
}
..finally, we need to declare those two new conditional functions:
function PaymentConstructorNoUib($injector, PaymentService, $scope, $rootScope) {
PaymentConstructor($injector, PaymentService, $scope, $rootScope, null);
}
function PaymentConstructorWithUib($injector, PaymentService, $scope, $rootScope, $modalInstance) {
PaymentConstructor($injector, PaymentService, $scope, $rootScope, $modalInstance);
}
//original controller function:
function PaymentConstructor($injector, PaymentService, $scope, $rootScope, $modalInstance) {
// if $modalInstance is null then we are not in modal dialog
$scope.view = '';
...
That's it. Tested. Works like a charm.