在EmberJS中将观察者与装饰器一起使用

时间:2020-05-29 10:58:03

标签: javascript ember.js decorator

我试图将观察者与装饰器语法一起使用,但这似乎不起作用。

没有装饰器:

onRouteChange: observer('router.currentRouteName', function () {
  this.closeModal();
}),

与装饰器一起尝试(失败):

@observer('router.currentRouteName')
handler() {
  this.closeModal();
}

错误消息:

断言失败:必须向观察者提供函数或观察者定义

我可能错过了一些东西,但是我没有在文档中找到关于装饰者和观察者的任何东西。

1 个答案:

答案 0 :(得分:3)

Ember没有提供开箱即用的observer装饰版本。

如果用例中没有您满意的迁移路径,则可以使用observer decorator from ember-decorators

请确保阅读quickstart,因为它包含了ember install ember-decorators以外的其他信息。

相关问题