3

I am using angular UI bootstrap and want to re-use the controller used in a modal dialog in a view that is not a dialog.

I tried to manually get the $modalInstance later via

$injector.get('$modalInstance'), but this does not work ( $injector.has('$modalInstance') equals false )

It only works when I directly inject it via

angular.module('mymodule').controller('MyModalCtrl', function($modalInstance) {
  // do something with $modalInstance
});

Is there a way to re-use the controller-code or do I have to write two separate controllers?

chmanie
  • 5,016
  • 3
  • 21
  • 28

1 Answers1

0

I found a trick to reuse the modal controller by passing the modalInstance through caller's $scope, so you won't have Unknown provider problem.

I answered it here: Passing modalInstance through $scope

Community
  • 1
  • 1
KinoP
  • 1,532
  • 15
  • 23