Skip to content

Instantly share code, notes, and snippets.

@brunokrebs
Created March 2, 2017 14:29
Show Gist options
  • Save brunokrebs/7ba9434d2e43cf412592bfa4edd8f14e to your computer and use it in GitHub Desktop.
Save brunokrebs/7ba9434d2e43cf412592bfa4edd8f14e to your computer and use it in GitHub Desktop.
// ... other imports
import { Http, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';
import { TaskListService } from './task-list/task-list.service';
// creates a factory to AuthHttp
export function authHttpFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig(), http, options);
}
@NgModule({
// ... other properties
providers: [
AuthService,
TaskListService, // adds new service
{
provide: AuthHttp,
useFactory: authHttpFactory, // defines how to provide AuthHttp
deps: [ Http, RequestOptions ]
}
],
bootstrap: [AppComponent]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment