javascript - Angular2 模块没有导出成员

标签 javascript angular typescript angular2-modules

对于在 Angular2 中进行身份验证的网站,我想在主应用程序组件中使用身份验证子模块的一个组件。但是,我不断收到以下错误:

app/app.component.ts(3,10): error TS2305: Module '"<dir>/app/auth/auth.module"' has no exported member 'SigninComponent'.

即使在导出 SigninComponent 之后。

项目文件夹结构如下图:

enter image description here

app/auth/auth.module.ts:

import { NgModule }       from '@angular/core';
import { CommonModule }   from '@angular/common';
import { FormsModule }    from '@angular/forms';

import { RegisterComponent }    from './components/register.component';
import { SigninComponent }    from './components/signin.component';
import { HomeComponent }    from './components/home.component';

import { AuthService } from './services/auth.service';
import { AuthHttp } from './services/auth-http';

@NgModule({
  imports: [
      CommonModule,
      FormsModule
  ],
  declarations: [
      RegisterComponent,
      SigninComponent,
      HomeComponent
  ],
  providers: [
      AuthService,
      AuthHttp
  ],
  exports: [
      RegisterComponent,
      SigninComponent,
      HomeComponent
  ]
})
export class AuthModule {}

app/auth/components/signin.component.ts:

import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../services/auth.service';

@Component({
    selector: 'signin',
    templateUrl: 'app/auth/signin.html'
})
export class SigninComponent {
    ...
}

app/app.component.ts:

import { Component, OnInit } from '@angular/core';
import { Router, RouterOutlet } from '@angular/router';
import { SigninComponent, RegisterComponent } from './auth/auth.module';
import { AuthHttp } from './auth/services/auth-http';
import { AuthService } from './auth/services/auth.service';

@Component({
    selector: 'myapp',
    templateUrl: 'app/app.html'
})

export class AppComponent implements OnInit {
    ...
}

app/app.module.ts:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }   from '@angular/forms';
import { HttpModule }    from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AuthModule } from './auth/auth.module';

import { AppComponent } from './app.component';

import { AuthService } from './auth/services/auth.service';
import { AuthHttp } from './auth/services/auth-http';

@NgModule({
  declarations: [
      AppComponent,
      AuthService,
      AuthHttp
  ],
  bootstrap: [ AppComponent ],
  imports : [
      BrowserModule,
      FormsModule,
      HttpModule,
      AuthModule,
      AppRoutingModule
  ],
  providers: [
      AuthService,
      AuthHttp
  ]
})
export class AppModule {
}

最佳答案

使用 atom (1.21.1 ia32)...我得到了同样的错误,即使我在 app.module.ts 和 app.module.ts 中的声明中添加了对我的管道的引用

解决方案是重新启动我的节点实例...停止网站然后再次执行 ng serve...重新启动后转到 localhost:4200 就像一个魅力

关于javascript - Angular2 模块没有导出成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41264962/

相关文章:

javascript - String.prototype.replace === String.replace

javascript - jQuery拒绝某些字符输入

javascript - 如何在没有 "restarting"进程的情况下重新加载 sails.js 应用程序?

html - 在 Angular 6 中编写自定义表格过滤器

javascript - 尝试在我的 React/TypeScript 组件中引用模拟数据对象,同时还将匹配类型导入为 Props

reactjs - Webpack 热重载在错误输入错误时停止

javascript - 我需要从输入中用红色 jquery 为字符串中的每个第二个字母着色

css - Angular 8 - Kendo TextArea 组件中的 formControlName

node.js - Angular 5 中的数据未存储在 localStorage 中

javascript - TypeScript 的方法别名