我有以下订阅者(在 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();
}
}
在构造函数中订阅者是未定义的。为什么会这样?