我有兩個服務:PlatformService
和AccountService
:無法解決所有參數PlatformService:([目標對象],[目標對象]?)
import {Http} from '@angular/http';
import {AccountService} from "./account.service";
import {ToastService} from "./toast.service";
@Injectable()
export class PlatformService {
constructor(
private http: Http,
private accountSvc: AccountService,
private toastSvc: ToastService
) {}
//...
}
import {Http} from "@angular/http";
import {ToastService} from "./toast.service";
@Injectable()
export class AccountService {
constructor(
private http: Http,
private toastService: ToastService
){}
//...
}
這是providers
在app.module.ts
:
providers: [
StatusBar,
SplashScreen,
ToastService,
AccountService,
PlatformService,
SocketService,
ModelService,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
我要注入accountService
到我platformService
,但我得到了以下錯誤:
Can't resolve all parameters for PlatformService: ([object Object], ?, [object Object]).
我不認爲我的代碼中存在循環依賴,也許是因爲platformService
和accountService
都注入http
和toastService
?
當我在PlatformService
的構造函數中註釋了private accountSvc: AccountService,
後,此錯誤消失。
你如何將它們添加到'providers'中 – Skeptor
問題已更新,謝謝。 @Skeptor – awmleer
這對我來說看起來很完美,你確定導入是否正常,正確路徑 – Skeptor