我有以下订阅者(在aSubscriber.js中):
import {EventAggregator} from 'aurelia-event-aggregator';
export class Subscriber{
static inject = [EventAggregator];
constructor(eventAggregator){
this.eventAggregator = eventAggregator;
}
subscribe(){
this.eventAggregator.subscribe('myPublishChannelName', payload => {
//do something with the payload here
alert('got the message that has been published');
});
}
}
在我班上注册我的订阅者:
import {inject} from 'aurelia-framework';
import {subscriber} from './aSubscriber';
@inject(subscriber)
export class Welcome{
constructor(subscriber){
// this.subscriber = subscriber;
// this.subscriber.subscribe();
}
}
在构造函数中,订阅者未定义。为什么会这样?
答案 0 :(得分:3)
我没有设置ES6沙箱来确认这一点,但在导入时看起来你使用了错误的类名。将subscriber
更改为Subscriber
可让您访问导出的课程。