我正在angular 2.0
做一个项目。在app.module
文件中声明组件时会出现错误。
我无法识别出错的地方我正在使用VS code
进行编码。
错误如下 -
dashboard:20 Error: (SystemJS) Unexpected value 'HeroDesignComponent' declared by the module 'AppModule'
Error: Unexpected value 'HeroDesignComponent' declared by the module 'AppModule'
at eval
(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14725:29)
at Array.forEach (native)
at CompileMetadataResolver._loadNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14702:56)
at CompileMetadataResolver.loadNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14625:31)
at RuntimeCompiler._loadModules (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17420:43)
at RuntimeCompiler._compileModuleAndComponents (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17390:37)
at RuntimeCompiler.compileModuleAsync (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17380:23)
at PlatformRef_._bootstrapModuleWithZone (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:6454:29)
at PlatformRef_.bootstrapModule (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:6436:25)
at Object.eval (http://localhost:3000/app/main.js:4:53)
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js
at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14725:29)
at Array.forEach (native)
at CompileMetadataResolver._loadNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14702:56)
at CompileMetadataResolver.loadNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14625:31)
at RuntimeCompiler._loadModules (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17420:43)
at RuntimeCompiler._compileModuleAndComponents (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17390:37)
at RuntimeCompiler.compileModuleAsync (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17380:23)
at PlatformRef_._bootstrapModuleWithZone (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:6454:29)
at PlatformRef_.bootstrapModule (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:6436:25)
at Object.eval (http://localhost:3000/app/main.js:4:53)
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js
请帮助我。
英雄design.component.ts
import { Component } from '@angular/core';
import { hero1 } from './hero1';
@Component({
moduleId: module.id,
selector : 'my-design',
templateUrl : 'hero-design.component.html',
styleUrls : ['hero-design.component.css']
})
export class HeroDesignComponent{
subjects = ['Appointment', 'Interview', 'regarding a post'];
model =new hero1(1,'Tony','tony@gmail.com','9988776655',this.subjects[0]);
submitted = false;
onsubmit() { this.submitted = true }
newhero1() {
this.model = new hero1(1,'','','','');
}
}
app.module.ts
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { HeroDetailComponent } from './hero-detail.component';
import { HeroesComponent } from './heroes.component';
import { HeroDesignComponent } from './hero-design.component';
import { HeroService } from './Hero.service';
import { DashboardComponent } from './dashboard.component';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppRoutingModule
],
declarations: [
AppComponent,
DashboardComponent,
HeroDetailComponent,
HeroesComponent,
HeroDesignComponent
],
providers:[
HeroService
],
bootstrap: [
AppComponent
]
})
export class AppModule { }