# Getting application controller from application view

**URL:** <https://discuss.emberjs.com/t/getting-application-controller-from-application-view/6120>\
**Category:** Uncategorized\
**Created:** [August 22, 2014, 8:29am UTC](https://discuss.emberjs.com/t/getting-application-controller-from-application-view/6120 "2014-08-22T08:29:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlai0001](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dlai0001/32/15527_2.png) [@dlai0001](https://discuss.emberjs.com/u/dlai0001)\
**Post date:** [August 22, 2014, 8:29am UTC](https://discuss.emberjs.com/t/getting-application-controller-from-application-view/6120/1 "2014-08-22T08:29:46Z")

</div>

Hi, I have the following code. But seems like the this.get(‘controller’) is returning undefined. What is the correct way of getting a application controller from the application view.

```
didInsertElement: function(){

    //Add swipe listeners
    var hammertime = new Hammer(this.$()[0]);
    hammertime.get('swipe').set({ direction: Hammer.DIRECTION_HORIZONTAL });
    hammertime.on('swipe', function(ev) {
      console.log(ev);

      if(ev.direction === 4) {
        this.get('controller').send('nextPage');
      }
      else {
        this.get('controller').send('previousPage');
      }
    });

```

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [August 22, 2014, 8:49am UTC](https://discuss.emberjs.com/t/getting-application-controller-from-application-view/6120/2 "2014-08-22T08:49:49Z")

</div>

I cannot reproduce your issue [Ember Latest - JSFiddle - Code Playground](http://jsfiddle.net/NQKvy/1273/)

Edit: one thing that stands out is what is the context of `this` inside of the swipe callback? You may want to consider using `Ember.run.bind` there.

Example:

```nohighlight
hammertime.on('swipe', Ember.run.bind(this, function(ev) {
      console.log(ev);

      if(ev.direction === 4) {
        this.get('controller').send('nextPage');
      }
      else {
        this.get('controller').send('previousPage');
      }
}));

```

---

<div class="post-metadata">

**Author:** ![gerrit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gerrit/32/9140_2.png) [@gerrit](https://discuss.emberjs.com/u/gerrit)\
**Post date:** [August 22, 2014, 8:59am UTC](https://discuss.emberjs.com/t/getting-application-controller-from-application-view/6120/3 "2014-08-22T08:59:22Z")

</div>

Or this might help: [http://www.quirksmode.org/js/this.html](http://www.quirksmode.org/js/this.html)

---

<div class="post-metadata">

**Author:** ![dlai0001](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dlai0001/32/15527_2.png) [@dlai0001](https://discuss.emberjs.com/u/dlai0001)\
**Post date:** [August 22, 2014, 2:37pm UTC](https://discuss.emberjs.com/t/getting-application-controller-from-application-view/6120/4 "2014-08-22T14:37:03Z")

</div>

that’s it, I forgot to bind. Thanks.
