Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  34] [ 3]  / answers: 1 / hits: 190464  / 8 Years ago, wed, december 21, 2016, 12:00:00

For a website with authentication in Angular2, I want to use a component of the authentication submodule in the main app component. However, I keep getting the following error:



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



even after exporting SigninComponent.



The project folder structure is as shown below:



enter



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

More From » angular

 Answers
44

You do not need the line:



import { SigninComponent, RegisterComponent } from './auth/auth.module';


in your app.component.ts as you already included the AuthModule in your app.module.ts. AutModule import is sufficient to use your component in the app.



The error that you get is a TypeScript error, not a Angular one, and it is correct in stating that there is no exported member, as it searches for a valid EC6 syntax for export, not angular module export. This line would thus work in your app.component.ts:



import { SigninComponent } from './auth/components/signin.component';

[#59620] Monday, December 19, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kayap

Total Points: 634
Total Questions: 83
Total Answers: 110

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
;