注入 Aurelia class 时订阅者为空?

Subscriber is null when injected in Aurelia class?

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

}

在我的 class 注册订阅者中,我有:

import {inject} from 'aurelia-framework';
import {subscriber} from './aSubscriber';

 @inject(subscriber)    
 export class Welcome{

 constructor(subscriber){
    // this.subscriber = subscriber;
    // this.subscriber.subscribe(); 
  }   

}

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

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