答えて

5

は、あなたのコンストラクタ関数へのあなたの依存関係をリストinjectプロパティを追加します。

import {EventAggregator} from 'aurelia-event-aggregator'; 

export function Example(eventAggregator) { 
    console.log(eventAggregator); 
    return { 
    message: 'hello world' 
    }; 
} 

Example.inject = [EventAggregator]; 

例の実行:https://gist.run/?id=d60c5c7dfbf53e507aae47d6c05b7d36

あなたは静的inject財産あなたを追加するのではなく、手動injectデコレータを使用したい場合書くことができます:

import {EventAggregator} from 'aurelia-event-aggregator'; 
import {inject} from 'aurelia-dependency-injection'; 

export function Example(eventAggregator) { 
    console.log(eventAggregator); 
    return { 
    message: 'hello world' 
    }; 
} 

inject(EventAggregator)(Example); 

注:標準デコレータの「@」構文では、ES6クラスを使用する必要がありますので、近代化したいことがあります。

関連する問題