我正在Angular4中实现一个演示项目,我也是新的(Angular4)。我看过一个链接,Angular2 module has no exported member,但我无法解决这个问题。
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { VideoListComponent } from './training/video-list.component';
import { HomeComponent } from './training/home.component';
import { AddVideoComponent } from './training/add-video.component';
import { AboutusComponent } from './training/aboutus.component';
@NgModule({
declarations: [
AppComponent,
VideoListComponent,
HomeComponent,
AddVideoComponent,
AboutusComponent
],
imports: [
BrowserModule,
HttpModule,
FormsModule,
ReactiveFormsModule,
RouterModule.forRoot([
{path: 'home', component:HomeComponent},
{path: 'videos', component:VideoListComponent},
{path :'newvideo',component:AddVideoComponent},
{path: 'aboutus', component:AboutusComponent},
{path: '', redirectTo:'home',pathMatch:'full'},
{path: '**', redirectTo:'home',pathMatch:'full'}
])
],
bootstrap: [AppComponent]
})
export class AppModule { }
aboutus.component.ts
import { Component } from '@angular/core';
console.log('It works here');
@Component({
moduleId: module.id,
templateUrl: 'aboutus.html'
})
export class AboutusComponent {
s: string = "Hello";
constructor() {
console.log(this.s)
}
}
我想添加 AboutusComponent ,而不是让编译失败。
我想在angular4中添加新模块 请分享你的想法。
答案 0 :(得分:0)
您错过了AboutusComponent
。
应该是
import { Component } from '@angular/core';
console.log('It works here');
@Component({
selector: 'aboutus', // the selector is missing in your component
moduleId: module.id,
templateUrl: 'aboutus.html'
})
export class AboutusComponent {
s: string = "Hello";
constructor() {
console.log(this.s)
}
}