2

So, I have created a module, inside that module I have a Navbar component declared like this:

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


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

  constructor() { }

  ngOnInit(): void {
  }

}

In the module I have this

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UsuariosComponent } from './usuarios/usuarios.component';
import { ProductosComponent } from './productos/productos.component';
import { NavComponent } from './nav/nav.component';



@NgModule({
  declarations: [NavComponent, UsuariosComponent, ProductosComponent, ],
  imports: [
    CommonModule
  ],
  exports: [
    NavComponent,
    UsuariosComponent,
    ProductosComponent
  ],
})
export class DashboardModule { }

and in the module component html I have the selector like this:

<app-nav></app-nav>

<h1>Dashboard</h1>

then in my app-module.ts I have the module imported, here's the file

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

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { LandingHeadComponent } from './components/landing-head/landing-head.component';
import { ProyectosSliderComponent } from './components/proyectos-slider/proyectos-slider.component';
import { ProductosLandingComponent } from './components/productos-landing/productos-landing.component';
import { TestimoniosComponent } from './components/testimonios/testimonios.component';
import { FooterComponent } from './components/footer/footer.component';
import { InicioComponent } from './inicio/inicio.component';
import { ProyectosComponent } from './proyectos/proyectos.component';
import { ContactoComponent } from './contacto/contacto.component';
import { CatalogoComponent } from './catalogo/catalogo.component';
import { InicioSesionComponent } from './components/inicio-sesion/inicio-sesion.component';

import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AdminHomeComponent } from './components/admin-home/admin-home.component';
import { DashboardModule } from './dashboard/dashboard.module';



@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    LandingHeadComponent,
    ProyectosSliderComponent,
    ProductosLandingComponent,
    TestimoniosComponent,
    FooterComponent,
    InicioComponent,
    ProyectosComponent,
    ContactoComponent,
    CatalogoComponent,
    InicioSesionComponent,
    AdminHomeComponent
  ],
  imports: [
    DashboardModule,
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    HttpClientModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

And it keeps throwing this error

'app-nav' is not a known element:
1. If 'app-nav' is an Angular component, then verify that it is part of this module.
2. If 'app-nav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

2 <app-nav></app-nav>

Any suggestions? I've been battling this for hours :(

Edit: this is my module, perhaps I'm having an error in the way I handle this?

Module Structure

I want to archive something like this:

Idea

2
  • Your code looks good, Try restarting your CLI - Answer Commented Jun 6, 2020 at 8:24
  • Already done that, didn't work :( Commented Jun 6, 2020 at 8:25

2 Answers 2

2

You are importing NavComponent into two modules, you should just import it into DashboardModule and then import DashboardModule into AppModule.

I hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Solved!!

It turns out I was not declaring my component to the module!!!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.