3
クラスではなく関数をエクスポートするときに依存関係を挿入するにはどうすればよいですか?ES6クラスフィーチャーを使用せずにAureliaに依存関係を注入する方法
クラスではなく関数をエクスポートするときに依存関係を挿入するにはどうすればよいですか?ES6クラスフィーチャーを使用せずにAureliaに依存関係を注入する方法
は、あなたのコンストラクタ関数へのあなたの依存関係をリスト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クラスを使用する必要がありますので、近代化したいことがあります。