New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cyclic dependency in HTTP_INTERCEPTORS when using platform-server #23023
Comments
Try using the Injector to grab HttpClient, you shouldn't have any issues that way: get http() {
return this._injector.get(HttpClient);
}
constructor(private injector: Injector) { }
// somewhere else
this.http.get(); Hope that helps! |
Hey, thats what I'm doing for now and it works. I just thought that if it works for platform-browser (no cyclic dependencies) it should work for platform-server as well. Thanks for answer :) |
Still same error with angular 6.0.3, I'll try the injector solution |
I have this error as well on 6.0.3. But my interceptor is not using httpClient. import { REQUEST } from '@nguniversal/express-engine/tokens';
@Injectable()
export class RefererInterceptor implements HttpInterceptor {
constructor(@Optional() @Inject(REQUEST) private request) {}
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (this.request) {
const host = `${this.request.protocol}://${this.request.headers.host}`;
req = req.clone({
headers: req.headers.append('StSsrReferer', host)
});
return next.handle(req);
}
}
} |
Fixes angular#23023. When a HTTP Interceptor injects HttpClient it causes a DI cycle. This fix is to use Injector to lazily inject HTTP_INTERCEPTORS while setting up the HttpHandler on the server so as to break the cycle.
@Willovent - what's the exact DI exception message. Want to make sure it's the same issue. |
Fixes angular#23023. When a HTTP Interceptor injects HttpClient it causes a DI cycle. This fix is to use Injector to lazily inject HTTP_INTERCEPTORS while setting up the HttpHandler on the server so as to break the cycle.
Turn out it was not the interceptor that I linked, but an another one using a service using an httpClient. Sorry for that :( |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
When using platform-server and injecting service which uses HttpClient into HttpInterceptor the cyclic dependency error occurs.
Expected behavior
There shouldn't be any cyclic dependency error.
For platform-browser it was fixed after #18224
Minimal reproduction of the problem with instructions
Create service (DummyService) which uses HttpClient
Create HTTP_INTERCEPTORS interceptor and inject DummyService there
Environment
The text was updated successfully, but these errors were encountered: