Angular4给出没有导出成员(无法编译)

时间:2017-10-22 07:22:05

标签: angular angular2-routing

我正在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 ,而不是让编译失败。

我正在分享我的目录结构 enter image description here

它在浏览器中给我一些错误(在屏幕截图下方)。 enter image description here

我想在angular4中添加新模块 请分享你的想法。

1 个答案:

答案 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)
    }
}