Export modules at angular 8

Asked

Viewed 216 times

1

I am trying to export a module with your Components to use in the app-module, but I am having the following error when opening:

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

I created a module and within this module I created a Component, I put this same Component to be exported and imported the module in the app-module.

No module exported the Component:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AmbevModuleComponent } from './AmbevModule.component';
import { FormsModule } from '@angular/forms';

@NgModule({
  imports: [
    CommonModule,
    FormsModule
  ],
  declarations: [AmbevModuleComponent],
  exports: [AmbevModuleComponent] <- exportei aqui
})
export class AmbevModuleModule { }

My compoment:

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

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

  constructor() { }

  ngOnInit() {
  }

}

and the app.module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { ModalModule } from 'ngx-bootstrap/modal';

import { AppRoutingModule } from './app-routing.module';

import { AppComponent } from './app.component';
import { NavComponent } from './nav/nav.component';
import { AmbevModuleModule } from './AmbevModule/AmbevModule.module';

@NgModule({
   declarations: [
      AppComponent,
      NavComponent
   ],
       imports: [
      BrowserModule,
      BrowserAnimationsModule,
      BsDropdownModule.forRoot(),
      TooltipModule.forRoot(),
      ModalModule.forRoot(),
      AppRoutingModule,
      HttpClientModule,
      FormsModule,
      ReactiveFormsModule,
      AmbevModuleModule <- importei aqui
   ],
   providers: [],
   bootstrap: [
      AppComponent
   ]
})
export class AppModule { }

I put the following tag in app.component.html

<app-AmbevComponent></app-AmbevComponent>

1 answer

0


The problem is that you declared and exported the module itself AmbevModuleModule. Just adjust the declarations and the exports for the component AmbevComponentComponent:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AmbevModuleComponent } from './AmbevModule.component';
import { FormsModule } from '@angular/forms';

@NgModule({
  imports: [
    CommonModule,
    FormsModule
  ],
  declarations: [AmbevComponentComponent ], // <- Correção
  exports: [AmbevComponentComponent ] // <- Correção
})
export class AmbevModuleModule { }
  • Marcelo, thank you for the reply, in case I declared the Component inside the module and exported the same Component, is not right? I declared the Component and exported it into the module. In this case, the name is as Ambevmodulecomponent because it was created inside a directory called Ambevmodule.

  • @Ronaldoalves according to his post within the AmbevModuleModule has been declared and exported the module itself AmbevModuleComponent. For this reason your component has not been exported. Just change where I left it indicated to your component, AmbevComponentComponent, is declared inside the module and exported.

  • Solved, thanks a lot.

Browser other questions tagged

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