My routing module cannot find my component

Asked

Viewed 78 times

0

I am trying to apply Lazy loading on my application, but for some reason is not found importing the component I do in my component routing file by returning:

Uncaught Error: Component Custofixocomponent is not part of any Ngmodule or the module has not been Imported into your module.

custofixo.module.ts:

    import { DialogConfirmacaoExclusaoModule } from './../../dialogexclusao/dialog-confirmacao-exclusao.module';
    //Importação de módulos angular
    import { MyMaterialDesignModule } from '../../../app.materialdesign.module';
    import { MatMenuModule } from '@angular/material/menu';
    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { FormsModule } from '@angular/forms';
    import { HttpClientModule } from '@angular/common/http';
    import { NgxCurrencyModule } from "ngx-currency";
    import { ReactiveFormsModule } from '@angular/forms';
    import { LoadingModule } from '../../loading/loading.module';
    import { NgxMaskModule } from 'ngx-mask'
    import { MostraToastService } from '../../../services/mostratoast.service';
    import { CustoFixoRoutingModule } from './custofixo.routing.module';
    //Importação de componentes do módulo
    import { CustofixoComponent } from './custofixo.component';
    import { MatTooltipModule } from '@angular/material';
    import { CustosService } from '../../../services/custos.service';
    import { DialogConfirmacaoExclusao } from '../../dialogexclusao/dialog-exclusao.component';
    import { AuthService } from '../../../services/auth.service';
    import { svgInfoManModule } from '../../svgInfoMan/svgInfoMan.module';

    @NgModule({
      imports: [
        CustoFixoRoutingModule,
        CommonModule,
        FormsModule,
        LoadingModule,
        MyMaterialDesignModule,
        HttpClientModule,
        MatMenuModule,
        MatTooltipModule,
        ReactiveFormsModule,
        DialogConfirmacaoExclusaoModule,
        NgxCurrencyModule,
        NgxMaskModule,
        svgInfoManModule,
      ],
      exports:[
        CustofixoComponent
      ],
      declarations: [CustofixoComponent],
      entryComponents:[DialogConfirmacaoExclusao],
      providers:[
        CustosService,
        MostraToastService,
        AuthService
      ]
    })

export class CustoFixoModule { }

custofixo.routing.ts: This is where the error is generated, for some reason it does not recognize the import of the component Custofixocomponente. Am I forgetting something?

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CustofixoComponent } from './custofixo.component';




    const custoFixoRoutes: Routes = [
        {
            path: '', component: CustofixoComponent
        }
];

@NgModule({
    imports: [RouterModule.forChild(custoFixoRoutes)],
    exports: [RouterModule]
})

export class CustoFixoRoutingModule {}

My root module routing:

const dashboardRoutes: Routes = [
    {path: 'dash', component: DashboardComponent, canActivate: [AuthGuard],
    children: [
    { path: '', loadChildren: 'src/app/components/dashboard/bemvindo/bemvindo.module#BemVindoModule' },
    { path: 'home', loadChildren: 'src/app/components/dashboard/bemvindo/bemvindo.module#BemVindoModule' },
    { path: 'custofixo', loadChildren: 'src/app/components/dashboard/custofixo/custofixo.module#CustoFixoModule' }

The welcome module works correctly, however I have compared the two codes and they have no differences in relation to modules/ routing

  • I think you need to declare your Custofixocomponent in your Custofixoroutingmodule so he can find.

  • Declare component in my routing module? doesn’t make much sense, it is already declared in the component module

  • Your module should declare the components it uses... It is kind of redundant you use a component inside it that you use in another module that imports this module. Maybe your routes should be a component instead of a module.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.