私は指数関数的に成長する可能性が高いサービスを作成しています。コンポーネントを使用する@Injectableに別々のファイルを書き込んでロードしたいと考えています。通常は複数のサービスを作成して各コンポーネントをコンポーネントに注入するだけですが、コンポーネントがかなり重くなっているため、1つのサービスをロードしてこの中のすべての関数を処理できれば、 1つのサービス。私はちょうどいいものをgoogledしていないことを望んでいる、そしてこれはインポートほど簡単です。Angular 2/4 Injectionableでファイルを分割する
-configfns1.ts
-configfns2.ts(私はconfig.serviceとして利用したい複数のTSの機能が含まれている)
-config.service:
一般的なアイデアは、これらの線に沿って何かだろう.TS
import { Injectable } from '@angular/core'
//{{Possibly import functions here}}
@Injectable()
export class ConfigService {
//{{Or possibly load within the class}}
}
-config-view.component.ts
import { Component, OnInit } from '@angular/core';
import { ConfigService } from '../services/config.service';
@Component({
selector: 'app-config-view',
templateUrl: './config-view.component.html',
styleUrls: ['./config-view.component.scss']
})
export class ConfigViewComponent implements OnInit {
constructor(private configService: ConfigService){ }
ngOnInit() {
this.configService.configfn1(); //<---This would be a function loaded from configfns1.ts, and injected from config.service.ts
})
onClick() {
this.configService.configfn2(); //Another fn loaded from configfns2.ts
}
}
この方法は可能ですか?それとも、それぞれのサービスを個別に作成し、それぞれをコンポーネントにインポートするだけですか?