1
我有猴子修補我的路由器當前的路由組件存儲在一個會話變量:灰燼2.5觀察會話屬性更改
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的解決方案。
謝謝!