I’m not getting to use a module

Asked

Viewed 628 times

0

It turns out I’m trying to use a module and I’m not getting from this error below:

Uncaught Error: Unexpected directive 'BordaCreateComponent' imported by the module 'AppModule'. Please add a @NgModule annotation. at syntaxError

My App.module.ts

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

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

import { AppComponent } from './app.component';

import { UsuarioRoutingModule } from './usuario/usuario-routing.module';
import { UsuarioModule } from './usuario/usuario.module';
import { UsuarioLoginComponent } from './usuario/usuario-login/usuario-login.component';

import { BordaCreateComponent } from './borda/borda-create/borda-create.component';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import {HttpModule} from '@angular/http';

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    NgbModule.forRoot(),
    BordaCreateComponent
  ],
  exports: [
    AppComponent,
    FormsModule,
    ReactiveFormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

My Borda.module.ts

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

import { AppModule } from '../app.module';
import { BordaRoutingModule } from './borda-routing.module';
import { BordaListComponent } from './borda-list/borda-list.component';
import { BordaCreateComponent } from './borda-create/borda-create.component';

@NgModule({
  imports: [
    CommonModule,
    BordaRoutingModule,
    AppModule
   ],
  exports: [
    BordaCreateComponent,
    BordaListComponent
   ],
  declarations: [BordaCreateComponent, BordaListComponent]
})
export class BordaModule { }

1 answer

1


Within the NgModule.imports, you can list only modules, not components:

imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    NgbModule.forRoot(),
    BordaCreateComponent // <----- errado
]

Remove the reference BordaCreateComponente and refer to the module BordaModulo. Additionally, read about what should be imported on Ngmodules FAQ. An excerpt from the documentation (translation done by me):

What should I care?

Import NgModules whose public declarable classes (exported) you need to reference in the component models of this module.

  • thank you very much, that’s right, I’m studying Angular and still do not understand this business of modules after this became clearer now.

  • @And then consider marking the answer as accepted if it has completely solved your problem.

Browser other questions tagged

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