我有两个服务: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