我试图将观察者与装饰器语法一起使用,但这似乎不起作用。
没有装饰器:
onRouteChange: observer('router.currentRouteName', function () {
this.closeModal();
}),
与装饰器一起尝试(失败):
@observer('router.currentRouteName')
handler() {
this.closeModal();
}
错误消息:
断言失败:必须向观察者提供函数或观察者定义
我可能错过了一些东西,但是我没有在文档中找到关于装饰者和观察者的任何东西。
答案 0 :(得分:3)
Ember没有提供开箱即用的observer
装饰版本。
如果用例中没有您满意的迁移路径,则可以使用observer decorator from ember-decorators。
请确保阅读quickstart,因为它包含了ember install ember-decorators
以外的其他信息。