模块导入的意外值'undefined'

loc*_*zak 4 angular

我以为我明白了ngModule它是多么有效,但显然不是.我有3个模块:AppModule,AmpedFormsModuleAmpedCommonModule(在下面)问题是,当我尝试导入AmpedFormsModuleAmpedCommonModule它时给我这个错误,控制台日志给我未定义:

模块'AmpedCommonModule'导入的意外值'undefined'

我玩过进口但尝试了很多但没有取得任何成功.我还尝试创建另一个模块,并且尝试导入Common或Form模块的模块也存在同样的问题.正确方向的任何一点都非常感谢!

app.module.ts

import { NgModule }       from '@angular/core';
import { HttpModule }     from '@angular/http';
import { BrowserModule }  from '@angular/platform-browser';
import { RouterModule }   from '@angular/router';

import { ModalModule } from 'angular2-modal';
import { BootstrapModalModule } from 'angular2-modal/plugins/bootstrap';

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

import { AmpedFormsModule }       from './amped/forms/amped.forms.module';
import { AmpedCommonModule }      from './amped/common/amped.common.module';


import { routes,
  appRoutingProviders }  from './app.routes';

import
  { LocationStrategy, HashLocationStrategy} from '@angular/common';


@NgModule({
  imports:      [
    BrowserModule,
    AmpedFormsModule,
    AmpedCommonModule,
    HttpModule,
    ModalModule.forRoot(),
    BootstrapModalModule,
    routes
  ],
  declarations: [ AppComponent, HomepageComponent ],
  providers : [appRoutingProviders, {provide: LocationStrategy, useClass: HashLocationStrategy}],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

./amped/forms/amped.forms.module

import { NgModule }           from '@angular/core';
import { CommonModule }       from '@angular/common';
import { HttpModule }         from '@angular/http';
import {
  FormsModule,
  ReactiveFormsModule }       from '@angular/forms';

// ... imports

import { AmpedCommonModule }  from '../common/amped.common.module';


@NgModule({
  imports         : [ CommonModule, FormsModule, ReactiveFormsModule, HttpModule, AmpedCommonModule ],
  declarations    : [ ... declarations ],
  exports         : [ ... exports ],
  providers       : [ ... services ],
  entryComponents : [  ]
})
export class AmpedFormsModule {}
Run Code Online (Sandbox Code Playgroud)

./amped/common/amped.common.module

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

// ... imports

import { AmpedFormsModule } from '../forms/amped.forms.module';

console.log('CRUUD', AmpedFormsModule);

@NgModule({
  imports       : [BrowserModule, FormsModule, AmpedFormsModule],
  declarations    : [ ... declarations ],
  exports         : [ ... exports ],
  providers       : [  ],
})
export class AmpedCommonModule { }
Run Code Online (Sandbox Code Playgroud)

app.routes.ts

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { HomepageComponent }  from './app.homepage';

import { crudRoutes } from './amped/forms/amped.forms.routes';

export const appRoutes: Routes = [
  ...crudRoutes,
  { path: '', component: HomepageComponent, pathMatch: 'full' },
];

export const appRoutingProviders: any[] = [];

export const routes: ModuleWithProviders = RouterModule.forRoot(appRoutes);
Run Code Online (Sandbox Code Playgroud)

./amped/forms/amped.forms.routes

export const crudRoutes: Routes = [
  { path: 'edit/:model', component: AmpedCrudTableComponent },
  { path: 'edit/:model/:id', component: AmpedCrudFormComponent }
];
Run Code Online (Sandbox Code Playgroud)

mic*_*yks 8

很难说确切的问题,但建议很少,

1) 改变BroswerModuleCommonModuleAppCommonModule.Keep心中BroswerModule应该由进口AppModuleRootModule只.

@NgModule({
  imports       : [CommonModule, FormsModule],
  ...
})
Run Code Online (Sandbox Code Playgroud)

2)不确定,但似乎你通过将模块导入到彼此中来创建循环依赖,但是尽管如此表示不确定.

@NgModule({
  imports       : [FormsModule, AmpedFormsModule],      //<<< here
})

@NgModule({
  imports       : [ HttpModule, AmpedCommonModule ],    //<<< here
  ...
})
Run Code Online (Sandbox Code Playgroud)

3)如果AmpedFormsModuleAmpedCommonModule是懒惰的模块不忘记把默认的关键字class关键字前

eg. export default class AmpedFormsModule {}
Run Code Online (Sandbox Code Playgroud)