2015-04-17 37 views
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(); 
    } 

} 

在構造函數中的用戶是未定義。這是爲什麼發生?

+0

你應該驗證@wordword答案,你只是忘了大寫 – sam

回答

3

我沒有設置ES6沙箱來確認這一點,但它看起來像導入時使用的是錯誤的類名稱。將subscriber更改爲Subscriber應使您可以訪問您的導出類。