在Aurelia类中注入时,订阅者为null?

时间:2015-04-17 03:13:58

标签: javascript node.js aurelia

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

}

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

1 个答案:

答案 0 :(得分:3)

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