意想不到的价值' DecoratorFactory'由模块导入的“TempModule'

时间:2016-09-13 07:06:18

标签: angular

在我的示例应用程序中,我编写了一个功能模块" TempModule"和 下面是代码。

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

import { TempOneComponent } from './temp.one.component';
import { TempTwoComponent } from './temp.two.component';
import { tempRouting } from './temp.routing';



@NgModule({
declarations: [ TempOneComponent,
                TempTwoComponent],
imports: [ NgModule,
           CommonModule,
           tempRouting]
})

export class TempModule {}

我指的是根模块中的TempModule,下面是根模块代码

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

//-- routing import
import { routing,
         appRoutingProviders} from './app.routing'; 

//-- root component import
import { AppComponent } from './app.component';
import { AppAboutComponent } from './app-about.component';
import { AppCreatTicketComponent } from './tickets/    app.create-ticket.component';
import { AppOpenTicketComponent } from './tickets/app.open-ticket.component';
import { AppSearchTicketComponent } from './tickets/    app.search-ticket.component';
import { AppDashboardComponent } from './tickets/app.dashboard.component';
import { AppUsersComponent } from './users/app.users.component';

import { TempModule } from './tempModule/temp.module';

@NgModule({
    declarations: [AppComponent , 
    AppAboutComponent , 
    AppCreatTicketComponent,
    AppOpenTicketComponent,
    AppSearchTicketComponent,
    AppDashboardComponent,
    AppUsersComponent
    ],
    imports:       [BrowserModule ,
                    FormsModule ,
                    routing,
                    TempModule ],
    providers: [appRoutingProviders],
    bootstrap:    [AppComponent]

})

export class AppModule {}

当我运行应用程序时,"意外的值' DecoratorFactory'由模块导入的TempModule'"显示在浏览器控制台中。

知道这个错误的原因是什么?

3 个答案:

答案 0 :(得分:31)

您正尝试在decorator数组中导入imports。它应该只包含模块

@NgModule({
  declarations: [ TempOneComponent,
                TempTwoComponent],
  imports: [ NgModule, <== why is it here???
           CommonModule,
           tempRouting]
}) 
export class TempModule {}

答案 1 :(得分:4)

另一种可以看到此错误的方法是从错误的位置导入模块。例如:

import {CommonModule} from '@angular/core';  // wrong

应该是:

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

答案 2 :(得分:0)

通过在英雄详细信息组件中添加以下代码来解决。

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