Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
Cannot import my custom components in Angular

I am quite new to Angular and have a problem importing my components. I declaired a module where I get all the components in, to use it as a shared components module I use input component inside sidebar component, and sidebar component on the app module, works fine. The problem is when I want to use input component inside base page, I import the module and use the tag on the html side and visual studio code doesn't warn me anything, but when compiling, console tells me that 'app-input' is not a known element

In my project I have the following structure

App
|-pages
|--base
|
|-widgets
|--sidebar
|---sidebar.component.ts
|--input
|---input.component.ts
|--widgets.module.ts
|
|-app.module.ts

input.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-input',
  templateUrl: './input.component.html',
  styleUrls: ['./input.component.css']
})
export class InputComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }

}

widgets.module.ts

import { NgModule } from '@angular/core';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { InputComponent } from './input/input.component';



@NgModule({
  declarations:[
    HeaderComponent,
    FooterComponent,
    SidebarComponent,
    InputComponent
  ],
  exports:[
    HeaderComponent,
    FooterComponent,
    SidebarComponent,
    InputComponent
  ]
})
export class WidgetsModule { }

I coudn't find any solution on the internet (or coudn't figure out what's going on for sure) and I have been looking to solve it for a week. I look forward for your answers and thanks in advance

EDIT 1

base.module.ts

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

import { BaseRoutingModule } from './base-routing.module';
import { BaseComponent } from './base.component';
import { WidgetsModule } from 'src/app/widgets/widgets.module';


@NgModule({
  declarations: [
    BaseComponent
  ],
  imports: [
    CommonModule,
    BaseRoutingModule,
    WidgetsModule
  ]
})
export class BaseModule { }

EDIT 2

Correct the folder structure

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

This error is usually occures when you did not import the module, where you want to use that component. So the module which has the base page component should import the WidgetsModule.

about 4 years ago · Santiago Trujillo Relatório

0

add these lines in your app.module.ts file

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@NgModule({
  declarations:[
      HeaderComponent,
      FooterComponent,
      SidebarComponent,
      InputComponent
      ],
  imports : [  ----  ],

  schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
about 4 years ago · Santiago Trujillo Relatório

0

After reviewing your repository, I found out that your issue is that you've not imported the BaseModule inside your AppModule. Otherwise your logic was correct.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda