Tech: using angular 6, angular cli and typescript.
Scenario:
I have an app module and a core module
I want my app modules components to use the services from my core module.
My core module contains a list of services:
import { NgModule } from '@angular/core';
// Services
import { AuthService } from './services/auth.service';
@NgModule({
declarations: [
],
imports: [
],
providers: [
AuthService
]
})
export class CoreModule { }
This is my app module:
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
// Modules
import { CoreModule } from './core/core.module';
// Sections
import { COMPONENTS } from './components/index';
import { ROUTES } from './app.routes';
@NgModule({
declarations: [
AppComponent,
COMPONENTS
imports: [
CommonModule,
FormsModule,
BrowserModule,
HttpClientModule,
ReactiveFormsModule,
RouterModule.forRoot(ROUTES),
CoreModule
],
providers: [
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Note: As you can see, I'm importing the CoreModule.
This is my component from the app module (its calling the core module to get the AuthService):
import { Component } from '@angular/core';
// This Auth Service import not working (says service not exported)
import { AuthService } from '../../core/core.module';
@Component({
selector: 'app-contact',
templateUrl: './contact.component.html'
})
export class ContactComponent {
constructor(
private authService: AuthService
) {}
}
Issue: I'm trying to import a service into my app modules component called contact component like so:
import { AuthService } from '../../core/core.module';
Error I get:
Service not an exported member of core module.
Outcome: I want my contact component from app module to import the core module service called AuthService.