2

For a test, I want to create a modal instance, then access it's scope, using something like the following pseudo-codeL

var modalInstance = $modal.open({ ... })
var scope = modalInstance.getScope()

Of course, the modalInstance returned by $modal.open() as described in https://angular-ui.github.io/bootstrap/#/modal does not have a method like getScope().

Is there some other way to gain access to the scope object that a modal instance created?

This may be related to 24373220.

Lawrence I. Siden
  • 9,191
  • 10
  • 43
  • 56

1 Answers1

2

According to the link your provide, you can set your own scope for the modal, and then keep a reference on it:

var modalScope    = $scope.$new();
var modalInstance = $modal.open({scope: modalScope})
// You have a reference to the modal scope
floribon
  • 19,175
  • 5
  • 54
  • 66
  • You are right @floribon. I should have thought about that. I am trying to test a service that creates the scope inside it's method and returns a modal instance. I should add a scope variable as an optional parameter to the method so that I can test it. Thank you! – Lawrence I. Siden Dec 18 '15 at 17:15