我正在使用Ionic 2,自2.0.0版本以来,提供者/注入出现了一些问题。我得到的错误如下(不同的提供商,而不仅仅是这个):
未捕获错误:无法解析LoginRedirectService: (App, ?, AlertController)的所有参数。
解决我的提供者的注入似乎有一个问题,即使它们都用@Injectable装饰。
一个文件
@Injectable()
export class LoginRedirectService {
constructor(
public app:App,
//another provider, needed within this one - this cannot be resolved
public authService: AuthenticationService,
public alert:AlertController
)
//...
}
不同文件
@Injectable()
export class AuthenticationService {
constructor(public dataService:DataService){
//...
}
}
//...
等等
我还在app.module中添加了所有的提供商。t,按照它们必须注入的顺序:
//Ordered by dependencies, bottom is the most dependent on others
providers: [
HttpModule,
JsonpModule,
RssService,
EmergencyEmailService,
InAppBrowserService,
ExternalBrowser,
AppLauncherService,
LauncherPlaner,
LauncherSkype,
ConnectivityService,
MockRemoteDataService,
SoniaMirthRemoteDataService,
DataService,
AuthenticationService,
LoginRedirectService,
NewsStreamService,
SoniaBootstrapService
]
我的项目结构是这样的:
- src
- 应用程序
- app.module.ts
- app.component.ts
- 页
- 供应商
- 子文件夹
- …
- 应用程序
- 包。json等。
我已经尝试在需要的类的构造函数中显式调用@Inject,但也没有成功。
我真的不知道该怎么做,谢谢你的帮助,谢谢
模块不是提供者,它们驻留在导入中。试试上面的@peeskillet