在 EmberJS 中使用带有装饰器的观察者
Use observer with decorator in EmberJS
我尝试使用带有装饰器语法的观察者,但它似乎不起作用。
没有装饰器:
onRouteChange: observer('router.currentRouteName', function () {
this.closeModal();
}),
尝试使用装饰器(失败):
@observer('router.currentRouteName')
handler() {
this.closeModal();
}
错误信息:
Assertion Failed: observer must be provided a function or an observer definition
我可能遗漏了一些东西,但我没有在文档中找到任何关于装饰器和观察者的信息。
Ember 不提供开箱即用的 observer
装饰器版本。
如果您的用例没有您满意的迁移路径,您可以使用 observer decorator from ember-decorators。
请务必阅读 quickstart,因为其中包含 ember install ember-decorators
以外的一些信息。
我尝试使用带有装饰器语法的观察者,但它似乎不起作用。
没有装饰器:
onRouteChange: observer('router.currentRouteName', function () {
this.closeModal();
}),
尝试使用装饰器(失败):
@observer('router.currentRouteName')
handler() {
this.closeModal();
}
错误信息:
Assertion Failed: observer must be provided a function or an observer definition
我可能遗漏了一些东西,但我没有在文档中找到任何关于装饰器和观察者的信息。
Ember 不提供开箱即用的 observer
装饰器版本。
如果您的用例没有您满意的迁移路径,您可以使用 observer decorator from ember-decorators。
请务必阅读 quickstart,因为其中包含 ember install ember-decorators
以外的一些信息。