2017-05-03 46 views
0

的错误是非常简单的,我遇到的问题是得到一个错误说No provider for ReloginComponent无提供ReloginComponent角4

首先,这是我在做什么。我正在通过注入调用服务中的组件。

例子:

@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); 
     }; 
    } 

我想有一个弹出,如果用户通过得到一个错误发生了:if语句

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{} 

当所有的失败,我将它添加到app.module

在这一点上,我不知道它要我在哪里添加它。

+0

尝试private @Inject(ReloginComponent)relogin:ReloginComponent –

+0

确定错误消失了,但没有弹出。现在看看它。 – Drew1208

+0

添加为答案:) –

回答