typescript “.... 没有导出成员” - 导入组件时出错(Angular)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43212957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:25:26  来源:igfitidea点击:

"....has no exported member"-error in importing component (Angular)

angulartypescriptcomponents

提问by iamnotbatma

i am making a component called headerComponent and importing in app.component.ts but getting website/src/app/header/app.headerComponent"' has no exported member 'headerComponent' error my app.headerComponent.ts code is as follow

我正在制作一个名为 headerComponent 的组件并在 app.component.ts 中导入但获取 website/src/app/header/app.headerComponent"' 没有导出成员 'headerComponent' 错误我的 app.headerComponent.ts 代码如下

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

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

and app.component.ts code is as follows

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

采纳答案by Sajeetharan

You need to add the component to your module.ts

您需要将组件添加到 module.ts

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

then,

然后,

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

回答by Pavlo Kozachuk

Fixed similar error by updating the Typescript version

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