Getting application controller from application view

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');
      }
    });

I cannot reproduce your issue Ember Latest - JSFiddle - Code Playground

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:

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');
      }
}));

Or this might help: http://www.quirksmode.org/js/this.html

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