0

I've been playing around for a solid hour or two trying to get my app to work but I can't get a simple service injection to work anymore.

I have a core module which has the GlobalsService provided:

core.module.ts:

@NgModule({
  declarations: [
    CoreComponent,

    SiteHeaderComponent,

    // Pages
    DocumentationComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule.forRoot([
      {path: 'documentation', component: DocumentationComponent},
      {path: '', component: CoreComponent}
    ]),
    DocumentationModule,
    SharedModule
  ],
  providers: [
    GlobalsService,
    RegexService,
    UtilsService
  ],
  bootstrap: [CoreComponent]
})
export class CoreModule {}

But when I try to use it in site-header.component.ts:

import {Component} from '@angular/core';
import {GlobalsService} from '../../shared';

@Component({
  selector: 'site-header',
  templateUrl: './site-header.component.html',
  styleUrls: ['./site-header.component.scss']
})
export class SiteHeaderComponent {

  ns: string;

  constructor(private globals: GlobalsService) {
    this.ns = globals.ns;
  }
}

globals.service.ts:

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

@Injectable()

export class GlobalsService {

   // App namespacer
   ns: string = 'test';
}

It just tells me that it can't resolve the parameter for the GlobalsService although it can find the service because if I change the import of it from ../../shared it throws an error saying it can't find it, so that's not where the issue seems to be.

EDIT:

I have a shared folder which contains directives, pipes, services and shared modules. Inside it I use an index.ts file to export everything, hence why the path is only ../../shared and not ../../shared/services/globals.service.ts.

See image:

shared folder

shared/services/index.ts:

export * from './globals/globals.service';
export * from './regex/regex.service';
export * from './utils/utils.service';

shared/index.ts:

export * from './directives';
export * from './modules';
export * from './pipes';
export * from './services';

Can someone figure out what on earth I'm missing here?

Chrillewoodz
  • 27,055
  • 21
  • 92
  • 175

1 Answers1

1

I'm guessing you have to put file name from share folder

import {GlobalsService} from '../../shared/global.service';

instead

import {GlobalsService} from '../../shared';
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299