0
我有以下的用戶(在aSubscriber.js):在Aurelia課堂註冊時,訂閱者爲空?
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();
}
}
在構造函數中的用戶是未定義。這是爲什麼發生?
你應該驗證@wordword答案,你只是忘了大寫 – sam