【问题标题】:"....has no exported member"-error in importing component (Angular)“....没有导出的成员”-导入组件时出错(Angular)
【发布时间】:2017-08-29 23:48:09
【问题描述】:

我正在制作一个名为 headerComponent 的组件并在 app.component.ts 中导入,但得到 website/src/app/header/app.headerComponent"' has no export member 'headerComponent' 错误我的 app.headerComponent.ts 代码为关注

import { Component } from '@angular/core';

@Component({
 selector: 'header',
 templateUrl: './app/header/header.html'
 })
 export class headerComponent {}

和app.component.ts代码如下

import { Component } from '@angular/core';

 import { headerComponent } from './header/app.headerComponent';

 @Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
   })
   export class AppComponent {
   }

【问题讨论】:

标签: angular typescript components


【解决方案1】:

你需要将组件添加到你的module.ts

import { headerComponent } from './header/app.headerComponent';

那么,

@NgModule({
  imports: [
  ],
  declarations: [
    headerComponent 
  ]

【讨论】:

  • 从 '@angular/platform-b​​rowser' 导入 { BrowserModule };从'@angular/core'导入{ NgModule };从“@angular/forms”导入 { FormsModule };从“@angular/http”导入 { HttpModule };从'./app.component'导入{AppComponent};从'./header/app.headerComponent'导入{headerComponent}; @NgModule({ 声明: [ AppComponent, headerComponent ], 导入: [ BrowserModule, FormsModule, HttpModule ], 提供者: [], bootstrap: [AppComponent, headerComponent] }) 导出类 AppModule { }
  • 已经有 AppComponent 我应该在声明中添加 headerComponent 吗?
  • 还是同样的问题
  • 编译失败。 C:/Users/anonymous/Desktop/website/src/app/app.component.ts (3,10): 模块'"C:/Users/anonymous/Desktop/website/src/app/header/app.headerComponent" ' 没有导出的成员 'headerComponent'。
  • 从 '@angular/platform-b​​rowser' 导入 { BrowserModule };从'@angular/core'导入{ NgModule };从“@angular/forms”导入 { FormsModule };从“@angular/http”导入 { HttpModule };从'./app.component'导入{AppComponent};从'./header/app.headerComponent'导入{headerComponent}; @NgModule({ 声明: [ AppComponent, headerComponent ], 导入: [ BrowserModule, FormsModule, HttpModule ], 提供者: [], bootstrap: [AppComponent] }) 导出类 AppModule { }
【解决方案2】:

通过更新 Typescript 版本修复了类似错误

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 1970-01-01
    • 2018-09-25
    • 2022-06-21
    • 2018-05-22
    • 2017-03-30
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    相关资源
    最近更新 更多