xiaopang xiaopang - 1 year ago 111
AngularJS Question

angular ui modal can NOT refer to parent scope

i am using angular ui modal to create modal in my project.

Everything works fine until I need to refer to variable in parent scope. see plunker code

It seems like modal can't access parent scope. Is there anyway to overcome this?

Answer Source

Angular UI's modals use $rootScope by default (See the documentation here).

You can pass a scope parameter with a custom scope when you open the modal – e.g. scope: $scope if you want to pass the parent scope. The modal controller will create a sub-scope from that scope, so you will only be able to use it for your initial values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download