0
私は、角1.5/4ハイブリッドアプリの角4モジュールに古い角1.5サービスを注入しようとしています。私はそれ公開する場合、私はMyService
は私が提供する方法がわからないのparamを見込んでいるため new MyService()
でそれを初期する方法がありませんので私の場合、モジュールにサービスを注入するには?
MyService
は、静的メソッドを使用しています。
私のクラス(私の-service.class.ts)
import {Inject, Injectable} from '@angular/core';
@Injectable()
class MyService {
constructor(
@Inject('myOldService') private myOldService: any) {}
static getMyUrl() {
console.log(this.myOldService);
// complains
// Property 'myOldService' does not exist on type 'typeof MyService
return this.myOldService.getItemUrl();
}
}
export default MyService;
マイモジュール
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
...other import..
import MyService from './my-service.class';
console.log(MyService.getMyUrl())
//has error because getMyUrl has error.
@NgModule({
'imports': [
CommonModule
],
'declarations': [
MyComponent
],
'providers': [
MyService
]
})
export class MyModule {}
は基本的に私は、静的メソッドの中に私の古いサービスをinejctするかどうかはわかりません。どんな助け?どうもありがとう!