Ember cleanup on leaving route

匿名 (未验证) 提交于 2019-12-03 00:50:01

问题:

I want to make some cleanup when i leave route, like stopping timers. For that i need an event that triggers when leaving the route, and i need access to instance of controller inside of that event.

There is an exit event, but it doesn't get any arguments, and this.get('controller') inside it doesn't work too - returns undefined.

Is there a proper way for obtaining controller instance in the exit event, or, maybe, another event that i don't know of?

I setup this fiddle with an example of what i want..

回答1:

You can achieve this by calling this.controllerFor('home'). You can try it in this JSFiddle.

This is a little bit annoying, so a pull request has been merged recently that allows you to directly use this.controller, as you can see in this JSFiddle.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!