Angle interceptor only works on main module

0

I have an angled interceptor 6 it works normally when I import into the main module (APP MODULE) but when I import into the ADM module it does not intercept anything. I would like to intercept only requests from my ADM module and not from every application.

I have an illustration of how my code is organized too:

I'vetriedseveralsolutionsandnoneworked,I'llsendmycode:

APPMODULE

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

import { AppComponent } from './app.component';
import { RoutingModule } from './routing.module';
import { HomeComponent } from './public/home/home.component';
import { NotFound404Component } from './public/not-found404/not-found404.component';

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    NotFound404Component
  ],
  imports: [
    BrowserModule,
    RoutingModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

ROUTING MODULE

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { HomeComponent } from './public/home/home.component';
import { NotFound404Component } from './public/not-found404/not-found404.component';
import { AuthGuardPainelAdmService } from './administrar/guards/auth-guard-painel-adm.service';


const routes: Routes = [
  //Rotas Publicas Com Lazy Load
  { 
    path: '', //vazio pois pega o valor das rotas filhas
    loadChildren: 'src/app/public/public.module#PublicModule'
  },
  //Rotas Adm Com Lazy Load
  { 
    path: 'administrar', 
    loadChildren: 'src/app/administrar/administrar.module#AdministrarModule',
    canActivate: [AuthGuardPainelAdmService]
  },
  //rotas que não tem lazy load
  { path: 'home', component: HomeComponent },
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  { path: '**', component: NotFound404Component },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})

export class RoutingModule { }

ADM MODULE

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { RoutingAdmModule } from './routing-adm.module';
import { HomePainelModule } from './gerenciarPainelAdm/home-painel/home-painel.module';
import { GerenciarLoginModule } from './gerenciarPainelAdm/gerenciar-login/gerenciar-login.module';
import { InterceptorModule, HttpsRequestInterceptor } from './interceptor.module';
import { VerificaLogadoService } from './verifica-logado.service';
import { AuthGuardPainelAdmService } from './guards/auth-guard-painel-adm.service';

@NgModule({
  imports: [
    CommonModule,
    RoutingAdmModule,
    HomePainelModule,
    GerenciarLoginModule,
    InterceptorModule,
  ],
  providers:[
   VerificaLogadoService,
   AuthGuardPainelAdmService
  ]
})
export class AdministrarModule { }

INTERCEPTOR

import { NgModule, Injectable } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HTTP_INTERCEPTORS } from '@angular/common/http';
import { Observable } from '../../../node_modules/rxjs';

@Injectable()

export class HttpsRequestInterceptor implements HttpInterceptor {
 intercept(
  req: HttpRequest<any>,
  next: HttpHandler,
 ): Observable<HttpEvent<any>> {
  const dupReq = req.clone({
   headers: req.headers.set('Authorization', window.sessionStorage.getItem('token')),
 });
 return next.handle(dupReq);
 }
}

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [],
  providers: [
    {
     provide: HTTP_INTERCEPTORS,
     useClass: HttpsRequestInterceptor,
     multi: true
    },
   ],
})
export class InterceptorModule { }

ROUTING ADM

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { HomePainelComponent } from './gerenciarPainelAdm/home-painel/home-painel.component';
import { GerenciarLoginComponent } from './gerenciarPainelAdm/gerenciar-login/gerenciar-login.component';

const rotasAdm: Routes = [
  { path: 'home', component: HomePainelComponent },
  { path: 'gerenciar-login', component: GerenciarLoginComponent }
];
@NgModule({
  imports: [RouterModule.forChild(rotasAdm)],
  exports: [RouterModule]
})
export class RoutingAdmModule { }
    
asked by anonymous 12.11.2018 / 14:26

0 answers