0

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

}

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

4

1 回答 1

3

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

于 2015-04-17T04:07:49.453 回答