t00f
t00f

Reputation: 573

How to propagate directive scope to parent scope using modal angular ui?

I read a lot of articles and AngularJS documentation but I could not find any way to propagate my directive scopes modification to my modal controller.

Here is easier version of the context :

I am able to retrieve the model from the modal controller, change it within my directive but when it comes to update parent scope, I always get the default model value.

I tried to used both inherited or isolated scope but I can't see what I am missing. Should anyone help me on this ?

Here is a very detailed planker : http://plnkr.co/edit/t3ecXakeJMlttQkj9GLM?p=preview

To reproduce the problem :

  1. Click on button "Open Modal"
  2. Modal opens and displays default model value "AAA"
  3. Enter "BBB", modal displays "BBB" (directive scope)
  4. Click "Close" button
  5. Main Ctrl is still displaying "AAA" value

Thanks for your help

t00f

Upvotes: 1

Views: 1571

Answers (1)

Fogia
Fogia

Reputation: 137

you should pass a "sub.model" to your model scope here is a working plunkr http://plnkr.co/edit/vXmgbVdYGrxbxYTIZVUU?p=preview

you'll see in the modal controller that instead of use $scope.model = 'AAA' directly as a string i used $scope.model = {data : 'AAA'} and I directly pass model.data into my-directive in modal.html

you'll get more explanation in this answer

Hope it'll help you

Upvotes: 4

Related Questions