ReloginComponent angular 4没有提供程序
这个错误非常直截了当,我遇到的问题是出现了一个错误,说ReloginComponent没有提供程序 首先,这就是我正在做的。我通过注入调用服务内部的组件 例如:ReloginComponent angular 4没有提供程序,angular,Angular,这个错误非常直截了当,我遇到的问题是出现了一个错误,说ReloginComponent没有提供程序 首先,这就是我正在做的。我通过注入调用服务内部的组件 例如: @Injectable() export class HttpUtil { constructor(private http: Http, private relogin: ReloginComponent) { } private catchAuthError (self: HttpUtil) { //
@Injectable()
export class HttpUtil {
constructor(private http: Http, private relogin: ReloginComponent) { }
private catchAuthError (self: HttpUtil) {
// we have to pass HttpService's own instance here as `self`
return (res: Response) => {
if (res.status === 401 || res.status === 403 || res.status === 500) {
//TODO: route the user to the login page again and make a 500 ERROR page
// if not authenticated
console.log("ERROR: "+res);
this.relogin.showDialog();
}
return Observable.throw('Not authenticated: '+res);
};
}
如果用户通过以下方式获得错误,我将尝试弹出窗口:
this.relogin.showDialog()
这是我的ReloginModule
@NgModule({
imports:[
DialogModule
],
declarations:[
ReloginComponent
],
exports: [
ReloginComponent,
],
providers: [
ReloginService
]
})
export class ReloginModule {
}
我甚至尝试将其添加到ServiceModule:
@NgModule({
imports:[
SmartadminModule,
ReloginModule
],
exports: [
],
providers:[
ReloginService
]
})
export class ServicesModule{}
当所有这些都失败时,我将其添加到应用程序模块
此时,我不知道它希望我将其添加到哪里。您必须添加@Inject,以便解决其依赖关系
因此,对于服务中的自定义服务,使用@Inject注入其依赖项
特定于您的代码:
private @Inject(ReloginComponent) relogin: ReloginComponent
你可以从这个博客中深刻地理解它 尝试private@Inject(ReloginComponent)relogin:ReloginComponentOk错误消失,但没有弹出窗口。现在查看。添加为答案:)