【发布时间】:2017-04-08 18:18:52
【问题描述】:
我已经为我的路由器打了猴子补丁,以将当前路由组件存储在会话变量中:
var Router = Ember.Router.extend({
customSession: Ember.inject.service('session-custom'),
location: config.locationType,
didTransition: function() {
this._super(...arguments);
this.get('customSession').set('currentEntity', this.get('currentRouteName').split('.')[0]);
this.get('customSession').set('currentDetailView', this.get('currentRouteName').split('.')[1]);
}
});
我知道这不是最干净的解决方案,但是将会话写入控制台证明至少设置了这些参数。
在我的控制器中,我想监听这些参数的变化,但不知何故这不起作用:
import Ember from 'ember';
import ApplicationController from './application';
export default ApplicationController.extend({
customSession: Ember.inject.service('session-custom'),
currentRouteNameChanged: Ember.observer('customSession.currentEntity', function () {
console.log("route changed");
})
});
即“路由已更改”永远不会打印到控制台。
这似乎很容易解决,但我无法在 SO 上找到解决方案。
谢谢!
【问题讨论】:
标签: session ember.js observers