Angular http client interceptors not known in lazy loaded feature module












0














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.










share|improve this question






















  • 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
















0














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.










share|improve this question






















  • 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














0












0








0







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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












1 Answer
1






active

oldest

votes


















0














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
],





share|improve this answer





















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


    }
    });














    draft saved

    draft discarded


















    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









    0














    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
    ],





    share|improve this answer


























      0














      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
      ],





      share|improve this answer
























        0












        0








        0






        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
        ],





        share|improve this answer












        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
        ],






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 19:34









        Fateh Mohamed

        5,07311124




        5,07311124






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...