[翻译]  Angular 2 Module has no exported member

[CHINESE]  Angular 2 Module没有导出成员


Here I am again, hoping to find a quick solution to this:

在这里,我再次希望找到一个快速解决方案:

Link <- Click on this link to see the folder structure

链接< - 单击此链接可查看文件夹结构

//main.ts
import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './home.main';
import {InputComponent} from './home.controller';
import {enableProdMode} from 'angular2/core';


bootstrap(InputComponent);
bootstrap(AppComponent);

This is my main.ts file where I import the AppComponent from home main, now the home.main looks like this:

这是我的main.ts文件,我从home main导入AppComponent,现在home.main看起来像这样:

import {Component} from 'angular2/core';

    @Component({
    selector:'home',
    templateUrl:'/index/index.ejs'
    })

    export class InputComponent {
      name = 'test';
     }

However, when I run this, I get: error TS2305: Module '"controllers/home/home.main"' has no exported member 'AppComponent'. ( Same goes for home.controller ).

但是,当我运行它时,我得到:错误TS2305:模块'“controllers / home / home.main”'没有导出成员'AppComponent'。 (同样适用于home.controller)。

Thank you, Alex S.

谢谢Alex S.

3 个解决方案

#1


4  

You should have something like that in your home.main module:

你应该在你的home.main模块中有这样的东西:

@Component({
  (...)
})
export class AppComponent {
}

#2


3  

If you see this error in any @angular modules like router, core, then make sure it is because of the version mismatch of the libraries. Generally all your @angular modules should be of the same version except router.

如果您在任何@angular模块(如路由器,核心)中看到此错误,请确保它是由于库的版本不匹配。通常,除路由器外,所有@angular模块都应该是相同的版本。

for Ex:

对于Ex:

    "@angular/common": "2.2.3",
    "@angular/compiler": "2.2.3",
    "@angular/core": "2.2.3",
    "@angular/platform-browser": "2.2.3",
    "@angular/platform-browser-dynamic": "2.2.3",
    "@angular/router": "^3.3.0" <= Version mismatch***

the following combination throws following error

以下组合会引发以下错误

has no exported member

没有导出的成员

I changed the router version to

我将路由器版本更改为

"@angular/router": "^3.0.0"

“@ angular / router”:“^ 3.0.0”

The error is resolved.

错误已解决。

So, until everything is stable stick with your working combination.

所以,直到一切都稳定坚持你的工作组合。

#3


0  

I had this issue even when I had correctly exported the class on my other file. Rebooting my machine fixed it.

即使我在其他文件上正确导出了类,我也遇到了这个问题。重新启动我的机器修复它。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号