Skip to content Skip to sidebar Skip to footer

Detecting Keypress In Ember.js V2+

I've problem with detecting keypress in ember v2.3.0. I'm beginer with ember and I try write simple component that display pressed key. But I got problem with run action and take p

Solution 1:

The official Ember.js guides have a section on handling events that should be helpful.

If you want your component to handle keydown you can do it like this:

importEmberfrom'ember';

exportdefaultEmber.Component.extend({
  didRender: function() {
    this.$().attr({ tabindex: 1 });
    this.$().focus();
  },
  shortcutKey: null,

  keyDown(event) {
    this.set('shortcutKey', String.fromCharCode(event.keyCode));
  }
});

See the full Ember Twiddle for the rest, but the template is the same as yours.

Post a Comment for "Detecting Keypress In Ember.js V2+"