代码之家  ›  专栏  ›  技术社区  ›  Varun Sharma

Angular4 give没有导出成员(编译失败)

  •  0
  • Varun Sharma  · 技术社区  · 8 年前

    我正在Angular4中实现一个演示项目,我在这方面也是新手(Angular4)。我看到了一个链接, Angular2 module has no exported member ,但我无法解决这个问题。

    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 { }
    

    关于。组成部分输电系统

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

    关于组件 比它给编译失败。

    enter image description here

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

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

    1 回复  |  直到 8 年前
        1
  •  0
  •   Rahul Singh    8 年前

    您错过了中的组件选择器 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)
        }
    }