Crabar
Crabar

Reputation: 1857

Access JQuery from Controller or Route

I have next structure:

I want to execute some jQuery code when template will be rendered. I found old solutions with View and didInsertElement, but I don't have View in this case. So, is it possible to execute jQuery code from route or controller?

jQuery code:

this.$("#filtersMenu").fixedsticky();

Upvotes: 2

Views: 793

Answers (1)

Kit Sunde
Kit Sunde

Reputation: 37075

You have didInsertElement on the view of the controller. If say you have IndexController then in views/index.js you would have:

export default Ember.View.extend({
  didInsertElement: function(){
    this.$('#filtersMenu').fixedsticky();
    this._super();
  }
});

JSFiddle: http://emberjs.jsbin.com/kegere/1/edit?html,js,output besides that globally jQuery is always on Ember.$:

Ember.$('#filtersMenu').fixedsticky();

That said you should consider putting this into a component that's entirely responsible for rendering it.

Upvotes: 2

Related Questions