我有以下订阅者(在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();
  }

}


在构造函数中,订户是未定义的。为什么会这样呢?

最佳答案

我没有设置ES6沙箱来确认这一点,但是看起来您在导入时使用了错误的类名。将subscriber更改为Subscriber应该可以访问导出的类。

10-05 21:04
查看更多