Angular http client interceptors not known in lazy loaded feature module
We have made an interceptor in Angular. This one is exported with a forRoot() in a core module. The app module imports this core module with forRoot().
In the lazy loaded feature module the interceptor is not known.
How can we fix this problem?
The http client module is imported only once in the app module.
angular angular-http-interceptors
|
show 2 more comments
We have made an interceptor in Angular. This one is exported with a forRoot() in a core module. The app module imports this core module with forRoot().
In the lazy loaded feature module the interceptor is not known.
How can we fix this problem?
The http client module is imported only once in the app module.
angular angular-http-interceptors
Did you provide your interceptor so that it is available on the module it will be used?
– GCSDC
Nov 22 at 16:33
The interceptor should be used on all modules. It is provided with a forRoot method in the core module and only the app module imports the core module.
– stephan.peters
Nov 22 at 16:34
I didn't get what you mean by providing it using forRoot. AFAIK you should provide it as { provide: HTTP_INTERCEPTORS, useClass: InterceptorClass, multi: true }. Also, did you try providing it directly on AppModule?
– GCSDC
Nov 22 at 16:39
I used the HTTP_INTERCEPTORS, multi: true... construction. And it is set in the CoreModule.forRoot()
– stephan.peters
Nov 22 at 16:41
I would suggest you: providing it on AppModule or importing core module also on lazy loaded modules or move the interceptor to a shared module and import it on any required modules.
– GCSDC
Nov 22 at 16:45
|
show 2 more comments
We have made an interceptor in Angular. This one is exported with a forRoot() in a core module. The app module imports this core module with forRoot().
In the lazy loaded feature module the interceptor is not known.
How can we fix this problem?
The http client module is imported only once in the app module.
angular angular-http-interceptors
We have made an interceptor in Angular. This one is exported with a forRoot() in a core module. The app module imports this core module with forRoot().
In the lazy loaded feature module the interceptor is not known.
How can we fix this problem?
The http client module is imported only once in the app module.
angular angular-http-interceptors
angular angular-http-interceptors
asked Nov 22 at 16:28
stephan.peters
343216
343216
Did you provide your interceptor so that it is available on the module it will be used?
– GCSDC
Nov 22 at 16:33
The interceptor should be used on all modules. It is provided with a forRoot method in the core module and only the app module imports the core module.
– stephan.peters
Nov 22 at 16:34
I didn't get what you mean by providing it using forRoot. AFAIK you should provide it as { provide: HTTP_INTERCEPTORS, useClass: InterceptorClass, multi: true }. Also, did you try providing it directly on AppModule?
– GCSDC
Nov 22 at 16:39
I used the HTTP_INTERCEPTORS, multi: true... construction. And it is set in the CoreModule.forRoot()
– stephan.peters
Nov 22 at 16:41
I would suggest you: providing it on AppModule or importing core module also on lazy loaded modules or move the interceptor to a shared module and import it on any required modules.
– GCSDC
Nov 22 at 16:45
|
show 2 more comments
Did you provide your interceptor so that it is available on the module it will be used?
– GCSDC
Nov 22 at 16:33
The interceptor should be used on all modules. It is provided with a forRoot method in the core module and only the app module imports the core module.
– stephan.peters
Nov 22 at 16:34
I didn't get what you mean by providing it using forRoot. AFAIK you should provide it as { provide: HTTP_INTERCEPTORS, useClass: InterceptorClass, multi: true }. Also, did you try providing it directly on AppModule?
– GCSDC
Nov 22 at 16:39
I used the HTTP_INTERCEPTORS, multi: true... construction. And it is set in the CoreModule.forRoot()
– stephan.peters
Nov 22 at 16:41
I would suggest you: providing it on AppModule or importing core module also on lazy loaded modules or move the interceptor to a shared module and import it on any required modules.
– GCSDC
Nov 22 at 16:45
Did you provide your interceptor so that it is available on the module it will be used?
– GCSDC
Nov 22 at 16:33
Did you provide your interceptor so that it is available on the module it will be used?
– GCSDC
Nov 22 at 16:33
The interceptor should be used on all modules. It is provided with a forRoot method in the core module and only the app module imports the core module.
– stephan.peters
Nov 22 at 16:34
The interceptor should be used on all modules. It is provided with a forRoot method in the core module and only the app module imports the core module.
– stephan.peters
Nov 22 at 16:34
I didn't get what you mean by providing it using forRoot. AFAIK you should provide it as { provide: HTTP_INTERCEPTORS, useClass: InterceptorClass, multi: true }. Also, did you try providing it directly on AppModule?
– GCSDC
Nov 22 at 16:39
I didn't get what you mean by providing it using forRoot. AFAIK you should provide it as { provide: HTTP_INTERCEPTORS, useClass: InterceptorClass, multi: true }. Also, did you try providing it directly on AppModule?
– GCSDC
Nov 22 at 16:39
I used the HTTP_INTERCEPTORS, multi: true... construction. And it is set in the CoreModule.forRoot()
– stephan.peters
Nov 22 at 16:41
I used the HTTP_INTERCEPTORS, multi: true... construction. And it is set in the CoreModule.forRoot()
– stephan.peters
Nov 22 at 16:41
I would suggest you: providing it on AppModule or importing core module also on lazy loaded modules or move the interceptor to a shared module and import it on any required modules.
– GCSDC
Nov 22 at 16:45
I would suggest you: providing it on AppModule or importing core module also on lazy loaded modules or move the interceptor to a shared module and import it on any required modules.
– GCSDC
Nov 22 at 16:45
|
show 2 more comments
1 Answer
1
active
oldest
votes
you have to import your coreModule in each LazyLoaded module to benefit from it's services and components
to make your services singleton, you import your coreModule in AppModule with .forRoot and in each lazyLoaded module without .forRoot,
so if it's your main module:
@NgModule({
imports: [
...
CoreModule.forRoot()
],
if it's a lazy loaded module
@NgModule({
imports: [
...
CoreModule
],
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435020%2fangular-http-client-interceptors-not-known-in-lazy-loaded-feature-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you have to import your coreModule in each LazyLoaded module to benefit from it's services and components
to make your services singleton, you import your coreModule in AppModule with .forRoot and in each lazyLoaded module without .forRoot,
so if it's your main module:
@NgModule({
imports: [
...
CoreModule.forRoot()
],
if it's a lazy loaded module
@NgModule({
imports: [
...
CoreModule
],
add a comment |
you have to import your coreModule in each LazyLoaded module to benefit from it's services and components
to make your services singleton, you import your coreModule in AppModule with .forRoot and in each lazyLoaded module without .forRoot,
so if it's your main module:
@NgModule({
imports: [
...
CoreModule.forRoot()
],
if it's a lazy loaded module
@NgModule({
imports: [
...
CoreModule
],
add a comment |
you have to import your coreModule in each LazyLoaded module to benefit from it's services and components
to make your services singleton, you import your coreModule in AppModule with .forRoot and in each lazyLoaded module without .forRoot,
so if it's your main module:
@NgModule({
imports: [
...
CoreModule.forRoot()
],
if it's a lazy loaded module
@NgModule({
imports: [
...
CoreModule
],
you have to import your coreModule in each LazyLoaded module to benefit from it's services and components
to make your services singleton, you import your coreModule in AppModule with .forRoot and in each lazyLoaded module without .forRoot,
so if it's your main module:
@NgModule({
imports: [
...
CoreModule.forRoot()
],
if it's a lazy loaded module
@NgModule({
imports: [
...
CoreModule
],
answered Nov 22 at 19:34
Fateh Mohamed
5,07311124
5,07311124
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435020%2fangular-http-client-interceptors-not-known-in-lazy-loaded-feature-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you provide your interceptor so that it is available on the module it will be used?
– GCSDC
Nov 22 at 16:33
The interceptor should be used on all modules. It is provided with a forRoot method in the core module and only the app module imports the core module.
– stephan.peters
Nov 22 at 16:34
I didn't get what you mean by providing it using forRoot. AFAIK you should provide it as { provide: HTTP_INTERCEPTORS, useClass: InterceptorClass, multi: true }. Also, did you try providing it directly on AppModule?
– GCSDC
Nov 22 at 16:39
I used the HTTP_INTERCEPTORS, multi: true... construction. And it is set in the CoreModule.forRoot()
– stephan.peters
Nov 22 at 16:41
I would suggest you: providing it on AppModule or importing core module also on lazy loaded modules or move the interceptor to a shared module and import it on any required modules.
– GCSDC
Nov 22 at 16:45