【问题标题】:Angular4 give has no exported member( Failed to compile)Angular4 give 没有导出的成员(编译失败)
【发布时间】:2017-10-22 07:22:04
【问题描述】:

我正在 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 中添加新模块 请分享你的想法。

【问题讨论】:

    标签: angular angular2-routing


    【解决方案1】:

    您错过了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)
        }
    }
    

    【讨论】:

    • AFAIK selector 是可选属性。默认为ng-component
    • @yurzui 我可能错了,但我不知道 id 选择器是可选的,在图片中没有其他东西能引起我的注意
    • @yurzui 现在这是我无法发现的鞠躬
    • @RahulSingh。我把你的代码,但同样的问题来了。
    • @VSH 你有 github repo 可以复制吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 2018-12-22
    • 2012-04-20
    • 2019-10-17
    • 2013-01-26
    • 1970-01-01
    相关资源
    最近更新 更多