Reputation: 563
i have a controller script in ember and iam using init() method in controller. this is my script
export default Ember.Controller.extend({
.....,
init() {
this._super(...arguments);
this.set('idUser', this.commonService.getUser().id);
Ember.$(document).ready(function () {
let height = Ember.$(window).height() - 96;
Ember.$(".feed-activity-list").slimScroll({
height: height.toString() + "px"
});
});
},
})
the init method is invoke when user first time open the page. but when user open another page and back to this page, the controller doesnt invoke the init() method. how to force the controller run init method when user visit this page. Iam avoid using component because its hard to refactor :(
Upvotes: 1
Views: 1213
Reputation: 12872
Controller is singleton so only one time init
will be called. You can make use of the corresponding route activate
hook or didTransition
hook. but its not guaranteed by that time DOM is ready. you might need to use Ember.run.next
or Ember.run.later('afterRender', () => { })
.
Use component
that is the ember best practise.
Upvotes: 4