# ionicModal $scope woes

**URL:** <https://forum.ionicframework.com/t/ionicmodal-scope-woes/18237>\
**Category:** ionic-v1\
**Created:** [February 25, 2015, 1:56pm UTC](https://forum.ionicframework.com/t/ionicmodal-scope-woes/18237 "2015-02-25T13:56:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenocon](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/zenocon/32/75472_2.png) [@zenocon](https://forum.ionicframework.com/u/zenocon)\
**Post date:** [February 25, 2015, 1:56pm UTC](https://forum.ionicframework.com/t/ionicmodal-scope-woes/18237/1 "2015-02-25T13:56:10Z")

</div>

Please see pen here: [http://codepen.io/anon/pen/xbjBvq](http://codepen.io/anon/pen/xbjBvq)

When you create a modal ala

```
  $ionicModal.fromTemplateUrl('modal.html', {
    scope: $scope,
    animation: 'slide-in-left'
  }).then(function (modal) {
     $scope.modal = modal;
  });

```

It would seem that the modal’s scope would be bound to the scope passed in via the options object

```
scope: $scope

```

But this is not the case, it seems. I haven’t looked at the source but I’m guessing the scope is isolate and therefore I cannot reference anything on the $parent controller’s scope, even in angular expressions, thus, the modal template buttons don’t work either way (with $parent or without):

```
<button ng-click="ok()">OK</button>
<button ng-click="$parent.cancel()">Cancel</button>

```

This used to work (I think) – what changed or what am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![cyprusglobe](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/cyprusglobe/32/64855_2.png) [@cyprusglobe](https://forum.ionicframework.com/u/cyprusglobe)\
**Post date:** [February 25, 2015, 3:32pm UTC](https://forum.ionicframework.com/t/ionicmodal-scope-woes/18237/2 "2015-02-25T15:32:01Z")

</div>

Hello @zenocon,

Try doing this

here is the codepen with my changes [http://codepen.io/anon/pen/myLYwJ](http://codepen.io/anon/pen/myLYwJ)

i noticed you had

```
<div class="modal" ng-controller="ModalCtrl">

```

meaning the modal has a separate controller from AppCtrl

what i did is this

```
app.controller('ModalCtrl', function($scope, $ionicModal) {
  $scope.ok = function () {
     alert('ok clicked');
     $scope.modal.hide();
  };
        
  $scope.cancel = function () {
    alert('cancel clicked');
    $scope.modal.hide();
  };
});

```

i hope i explained that well enough

Cheers

---

<div class="post-metadata">

**Author:** ![zenocon](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/zenocon/32/75472_2.png) [@zenocon](https://forum.ionicframework.com/u/zenocon)\
**Post date:** [February 25, 2015, 3:42pm UTC](https://forum.ionicframework.com/t/ionicmodal-scope-woes/18237/3 "2015-02-25T15:42:06Z")

</div>

> [@cyprusglobe](#):
>
> [http://codepen.io/anon/pen/xbjBvq](http://codepen.io/anon/pen/xbjBvq)

Thanks @cyprusglobe – I ended up resolving it too. I had forked a pen to create this, and I noticed some particular issues with it. I fixed it too: [http://codepen.io/anon/pen/xbjBvq](http://codepen.io/anon/pen/xbjBvq)

The template wasn’t using `<ion-modal-view>` directive – that seemed to be the root of the issue. Also, there was a typo in the controller, where I was referencing `modal.hide()` instead of `$scope.modal.hide()` – the significant issue seemed to be the lack of `<ion-modal-view>` directive. If you use this, and pass the controller’s scope, then you don’t need to define a separate controller for the modal.

---

<div class="post-metadata">

**Author:** ![cyprusglobe](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/cyprusglobe/32/64855_2.png) [@cyprusglobe](https://forum.ionicframework.com/u/cyprusglobe)\
**Post date:** [February 25, 2015, 6:05pm UTC](https://forum.ionicframework.com/t/ionicmodal-scope-woes/18237/4 "2015-02-25T18:05:49Z")

</div>

> [@zenocon](#):
>
> Thanks @cyprusglobe – I ended up resolving it too. I had forked a pen to create this, and I noticed some particular issues with it. I fixed it too: [http://codepen.io/anon/pen/xbjBvq](http://codepen.io/anon/pen/xbjBvq)
> 
> The template wasn’t using `&lt;ion-modal-view&gt;` directive – that seemed to be the root of the issue. Also, there was a typo in the controller, where I was referencing `modal.hide()` instead of `$scope.modal.hide()` – the significant issue seemed to be the lack of `&lt;ion-modal-view&gt;` directive. If you use this, and pass the controller’s scope, then you don’t need to define a separate controller for the modal.

glad to here you got it fixed 😄
