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

I don't have an ES6 sandbox set up to confirm this, but it looks like you are using the wrong class name when importing. Changing subscriber to Subscriber should give you access to your exported class.

于 2015-04-17T04:07:49.453 に答える