How to import Angular HTTP interceptor only for Child module
I have imported HttpClientModule in AppModule.
import HttpClientModule from '@angular/common/http';
export const AppRoutes: Routes = [
path: '', redirectTo: 'dashboard', pathMatch: 'full' ,
path: 'account',
loadChildren: './auth/auth.module#AuthModule'
,
path: 'dashboard',
loadChildren: './content/content.module#ContentModule'
];
Once I launch site, it will redirect to dashboard module(Lazy loaded module) where i added http interceptor.
import HTTP_INTERCEPTORS from '@angular/common/http';
import HttpInterceptorService from '../services/http-interceptor.service';
@NgModule(
providers : [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
)
But it doesn't working. Can anyone help me?
angular http httpclient interceptor angular-http-interceptors
add a comment |
I have imported HttpClientModule in AppModule.
import HttpClientModule from '@angular/common/http';
export const AppRoutes: Routes = [
path: '', redirectTo: 'dashboard', pathMatch: 'full' ,
path: 'account',
loadChildren: './auth/auth.module#AuthModule'
,
path: 'dashboard',
loadChildren: './content/content.module#ContentModule'
];
Once I launch site, it will redirect to dashboard module(Lazy loaded module) where i added http interceptor.
import HTTP_INTERCEPTORS from '@angular/common/http';
import HttpInterceptorService from '../services/http-interceptor.service';
@NgModule(
providers : [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
)
But it doesn't working. Can anyone help me?
angular http httpclient interceptor angular-http-interceptors
post appmodule ts
– Sajeetharan
Nov 14 '18 at 17:27
add a comment |
I have imported HttpClientModule in AppModule.
import HttpClientModule from '@angular/common/http';
export const AppRoutes: Routes = [
path: '', redirectTo: 'dashboard', pathMatch: 'full' ,
path: 'account',
loadChildren: './auth/auth.module#AuthModule'
,
path: 'dashboard',
loadChildren: './content/content.module#ContentModule'
];
Once I launch site, it will redirect to dashboard module(Lazy loaded module) where i added http interceptor.
import HTTP_INTERCEPTORS from '@angular/common/http';
import HttpInterceptorService from '../services/http-interceptor.service';
@NgModule(
providers : [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
)
But it doesn't working. Can anyone help me?
angular http httpclient interceptor angular-http-interceptors
I have imported HttpClientModule in AppModule.
import HttpClientModule from '@angular/common/http';
export const AppRoutes: Routes = [
path: '', redirectTo: 'dashboard', pathMatch: 'full' ,
path: 'account',
loadChildren: './auth/auth.module#AuthModule'
,
path: 'dashboard',
loadChildren: './content/content.module#ContentModule'
];
Once I launch site, it will redirect to dashboard module(Lazy loaded module) where i added http interceptor.
import HTTP_INTERCEPTORS from '@angular/common/http';
import HttpInterceptorService from '../services/http-interceptor.service';
@NgModule(
providers : [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
)
But it doesn't working. Can anyone help me?
angular http httpclient interceptor angular-http-interceptors
angular http httpclient interceptor angular-http-interceptors
asked Nov 14 '18 at 17:24
IndhuIndhu
2671315
2671315
post appmodule ts
– Sajeetharan
Nov 14 '18 at 17:27
add a comment |
post appmodule ts
– Sajeetharan
Nov 14 '18 at 17:27
post appmodule ts
– Sajeetharan
Nov 14 '18 at 17:27
post appmodule ts
– Sajeetharan
Nov 14 '18 at 17:27
add a comment |
1 Answer
1
active
oldest
votes
Http interceptor is just a service there won't be any difference in injecting it on any modules - just do the same in AppModule
that will help you to work - if in case you have the same problem you can try injecting like below on your shared module
The common pattern to achieve that is not to expose providers directly on the @NgModule
declaration but in a static forRoot function like that:
export class SharedModule
static forRoot(): ModuleWithProviders
return
ngModule: SharedModule,
providers: [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
;
You can then import your SharedModule
on AppModule
like SharedModule.forRoot()
Hope this works - Happy coding
Thanks for your effort. But actually it works after sometime.
– Indhu
Nov 15 '18 at 9:46
No problem :) Happy coding
– Rahul
Nov 15 '18 at 9:52
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%2f53305685%2fhow-to-import-angular-http-interceptor-only-for-child-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
Http interceptor is just a service there won't be any difference in injecting it on any modules - just do the same in AppModule
that will help you to work - if in case you have the same problem you can try injecting like below on your shared module
The common pattern to achieve that is not to expose providers directly on the @NgModule
declaration but in a static forRoot function like that:
export class SharedModule
static forRoot(): ModuleWithProviders
return
ngModule: SharedModule,
providers: [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
;
You can then import your SharedModule
on AppModule
like SharedModule.forRoot()
Hope this works - Happy coding
Thanks for your effort. But actually it works after sometime.
– Indhu
Nov 15 '18 at 9:46
No problem :) Happy coding
– Rahul
Nov 15 '18 at 9:52
add a comment |
Http interceptor is just a service there won't be any difference in injecting it on any modules - just do the same in AppModule
that will help you to work - if in case you have the same problem you can try injecting like below on your shared module
The common pattern to achieve that is not to expose providers directly on the @NgModule
declaration but in a static forRoot function like that:
export class SharedModule
static forRoot(): ModuleWithProviders
return
ngModule: SharedModule,
providers: [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
;
You can then import your SharedModule
on AppModule
like SharedModule.forRoot()
Hope this works - Happy coding
Thanks for your effort. But actually it works after sometime.
– Indhu
Nov 15 '18 at 9:46
No problem :) Happy coding
– Rahul
Nov 15 '18 at 9:52
add a comment |
Http interceptor is just a service there won't be any difference in injecting it on any modules - just do the same in AppModule
that will help you to work - if in case you have the same problem you can try injecting like below on your shared module
The common pattern to achieve that is not to expose providers directly on the @NgModule
declaration but in a static forRoot function like that:
export class SharedModule
static forRoot(): ModuleWithProviders
return
ngModule: SharedModule,
providers: [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
;
You can then import your SharedModule
on AppModule
like SharedModule.forRoot()
Hope this works - Happy coding
Http interceptor is just a service there won't be any difference in injecting it on any modules - just do the same in AppModule
that will help you to work - if in case you have the same problem you can try injecting like below on your shared module
The common pattern to achieve that is not to expose providers directly on the @NgModule
declaration but in a static forRoot function like that:
export class SharedModule
static forRoot(): ModuleWithProviders
return
ngModule: SharedModule,
providers: [
provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true
]
;
You can then import your SharedModule
on AppModule
like SharedModule.forRoot()
Hope this works - Happy coding
answered Nov 14 '18 at 17:42
RahulRahul
1,0972318
1,0972318
Thanks for your effort. But actually it works after sometime.
– Indhu
Nov 15 '18 at 9:46
No problem :) Happy coding
– Rahul
Nov 15 '18 at 9:52
add a comment |
Thanks for your effort. But actually it works after sometime.
– Indhu
Nov 15 '18 at 9:46
No problem :) Happy coding
– Rahul
Nov 15 '18 at 9:52
Thanks for your effort. But actually it works after sometime.
– Indhu
Nov 15 '18 at 9:46
Thanks for your effort. But actually it works after sometime.
– Indhu
Nov 15 '18 at 9:46
No problem :) Happy coding
– Rahul
Nov 15 '18 at 9:52
No problem :) Happy coding
– Rahul
Nov 15 '18 at 9:52
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.
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%2f53305685%2fhow-to-import-angular-http-interceptor-only-for-child-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
post appmodule ts
– Sajeetharan
Nov 14 '18 at 17:27