我正在构建的 Angular 2 应用程序遇到问题。我一直在从不同的位置练习复制/粘贴技能,并消除了所有构建错误,但是当我在浏览器中启动它时,浏览器中出现错误。我看过这个帖子 https://stackoverflow.com/questions/39685179/angular-2-no-ngmodule-metadata-found但它并没有解决我的问题。
My AppModule
看起来像这样:
import { NgModule, ApplicationRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { ROUTES } from './app.routes';
import { HomeComponent } from '../index';
@NgModule({
bootstrap: [ AppModule ],
declarations: [
AppModule,
HomeComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot(ROUTES, { useHash: true })
]
})
export class AppModule {
}
我是这样引导的:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './index';
platformBrowserDynamic().bootstrapModule(AppModule);
但在我的浏览器中,我收到此错误:
ng_module_resolver.js:34 未捕获错误:未找到“AppModule”的 NgModule 元数据。
我该如何解决这个问题?
Update
我的代码现在看起来像这样,但仍然生成错误:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { ROUTES } from './app.routes';
import { HomeComponent } from '../index';
import { AppComponent } from './app.component';
@NgModule( {
bootstrap: [ AppComponent ],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot( ROUTES, { useHash: true } )
],
declarations: [
HomeComponent,
AppComponent
]
} )
export class AppModule {
}
并引导:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppComponent } from './index';
platformBrowserDynamic().bootstrapModule(AppComponent);
这是我现在遇到的错误:
未捕获错误:未找到“AppComponent”的 NgModule 元数据
这是一个错误吗AppComponent
,或引导,或模块声明和元数据?文档含糊不清。