How should I bind to a window function in an Ember View?
I know I'm a few years late, but I was looking for a solution to the same problem and found this:
jQuery(window).on('resize', Ember.run.bind(this, this.handleResize));
(source: Ember.js ofiicial)
**** P.S. About the implementation of this little trick - I don't know if it's possible to use it in a controller method and trigger on init (as denis.peplin commented), I'm actually binding the event in the route's 'setupController' function. I don't know if it's best-practice, but it works like a charm in my app.
There's nothing wrong with registering your own event handler with jQuery for something like this.
Ember doesn't have any window event handling currently.
I'd also suggest trying to come up with a solution that didn't rely on globals.
And sample code for Itay Hamashmid
's answer:
App.ApplicationController = Ember.Controller.extend({
handleResize: function() {
console.log('resized');
},
bindResizeEvent: function() {
jQuery(window).on('resize', Ember.run.bind(this, this.handleResize));
}.on('init')
});