Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access service in app.module? #36

Closed
mackelito opened this issue Mar 3, 2017 · 1 comment
Closed

How to access service in app.module? #36

mackelito opened this issue Mar 3, 2017 · 1 comment

Comments

@mackelito
Copy link

I have a auth service that I want to access to set some values in restangularInit

export function restangularInit(RestangularProvider, AuthService) {
  RestangularProvider.setBaseUrl('api');
  RestangularProvider.setDefaultHeaders(
    {'Authorization': 'Bearer [replace this :) ]'},
  );
}

can´t find out how to use my AuthService.. it just stays "undefined"..
Any help is appreciated!

@mackelito
Copy link
Author

More code to give a better context..

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { HttpModule } from '@angular/http';
    import { MaterialModule } from '@angular/material';
    import { FlexLayoutModule } from "@angular/flex-layout";
    import { RestangularModule } from 'ng2-restangular';

    // Components
    import { AppComponent } from './app.component';
    import { ProductComponent } from './components/product/product.component';

    // Services
    import { AuthService } from './services/auth.service';

    export function restangularInit(RestangularProvider, AuthService) {
      console.log(AuthService);
      RestangularProvider.setBaseUrl('api');
      RestangularProvider.setDefaultHeaders(
        {'Authorization': 'Bearer d7b2e9f56a22646a22e1ee348ab2f85bdb967b56'},
      );
    }

    @NgModule({
      declarations: [
        AppComponent,
        ProductComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        MaterialModule,
        FlexLayoutModule,
        RestangularModule.forRoot(restangularInit)
      ],
      providers: [
        AuthService
      ],
      entryComponents: [ProductComponent],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant