意外的指令' LoginComponent'由模块' AppModule'导入。请添加@NgModule注释

时间:2017-06-24 15:05:15

标签: angular meteor

我正在使用Angular 2和Meteor。生成组件会产生以下错误:

Unexpected directive 'LoginComponent' imported by the module 'AppModule'. Please add a @NgModule annotation.  

app.module.ts文件是

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './app.component';
import { LoginComponent } from '../../components/login/login.component';
import { SignupComponent } from '../../components/signup/signup.component';
import { ResourcesComponent } from '../../components/resources/resources.component'; 
import { NavbarComponent } from '../../components/navbar/navbar.component';

@NgModule({
  declarations: [
    MyApp,
    LoginComponent,
    SignupComponent,
    ResourcesComponent
  ],
  entryComponents: [
    MyApp
  ],
  imports:[BrowserModule,
  LoginComponent,
  SignupComponent,
  ResourcesComponent
  ],
  bootstrap: [MyApp]
})
export class AppModule {}

和login.component.ts文件是

import 'zone.js';
import 'reflect-metadata';
import { Component } from '@angular/core';
import template from "./login.html";

@Component({
  selector: 'login',
  template
})
export class LoginComponent {}

1 个答案:

答案 0 :(得分:58)

NgModule.imports中,您只能列出模块。不是组件。问题出在这里:

imports:[BrowserModule, LoginComponent, SignupComponent, ResourcesComponent ]

删除组件,然后查看NgModules FAQ

  

我应该导入什么?

     

导入需要在此模块的组件模板中引用其公共(导出)可声明类的模块