# Ionic modal and img directive problem

**URL:** <https://forum.ionicframework.com/t/ionic-modal-and-img-directive-problem/21919>\
**Category:** ionic-v1\
**Created:** [April 29, 2015, 6:12pm UTC](https://forum.ionicframework.com/t/ionic-modal-and-img-directive-problem/21919 "2015-04-29T18:12:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arjunrc](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arjunrc/32/82541_2.png) [@arjunrc](https://forum.ionicframework.com/u/arjunrc)\
**Post date:** [April 29, 2015, 6:12pm UTC](https://forum.ionicframework.com/t/ionic-modal-and-img-directive-problem/21919/1 "2015-04-29T18:12:48Z")

</div>

Hi, I have written the following global directive in app.js --\> I want to trap all occurrences of img src or img ng-src in my code.

```
.directive('img', function () {
    return {
        restrict: 'E',
        link: function (scope, element, attrs) {
            console.log (" ********** IMG DIRECTIVE ");

        }
    }
})

```

What I am observing is that this is called every time I load any image in any view, but it does not get called when I load an image inside an ionic modal like this situation:

```
  <ion-content>
      <ion-scroll has-bouncing=false min-zoom=1 zooming="true" direction="xy" style="width: 100%; ">
            <img ng-src="{{loginData.url}}/cgi-bin/nph-zms?source=event&mode=jpeg&event={{eventId}}&frame=1&rate=100&maxfps=5&replay=single&user={{loginData.username}}&pass={{loginData.password}}&connkey={{connKey}}&rand={{rand}}" width="100%" />
        </ion-scroll>

```

The exact same img ng-src called outside of a modal works - i.e. the directive is called.

---

<div class="post-metadata">

**Author:** ![arjunrc](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arjunrc/32/82541_2.png) [@arjunrc](https://forum.ionicframework.com/u/arjunrc)\
**Post date:** [April 29, 2015, 6:30pm UTC](https://forum.ionicframework.com/t/ionic-modal-and-img-directive-problem/21919/2 "2015-04-29T18:30:00Z")

</div>

I’ve added a codepen

> **[Ionic Modal Example](https://codepen.io/asker/pen/YXXyZj?editors=101)**
>
> Shows How to open a modal. Forked from \[Ionic\](http://codepen.io/ionic/)'s Pen \[Ionic Sign-in, then Tabs: 0.9.27\](http://codepen.io/ionic/pen/kcjLb/)....

Click on “Open Modal” and the directive won’t be called when the image is loaded  
Click on the “CLICK HERE TO SEE IMAGE AND DIRECTIVE” link on the homepage and the directive is called

---

<div class="post-metadata">

**Author:** ![arjunrc](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arjunrc/32/82541_2.png) [@arjunrc](https://forum.ionicframework.com/u/arjunrc)\
**Post date:** [April 30, 2015, 2:02am UTC](https://forum.ionicframework.com/t/ionic-modal-and-img-directive-problem/21919/3 "2015-04-30T02:02:14Z")

</div>

Solved the problem – the directive was being called, but during controller load, not during modal show because I was pre-instantiating it.
