Skip to content

Instantly share code, notes, and snippets.

@chbaranowski
Created January 21, 2017 21:30
Show Gist options
  • Save chbaranowski/5a786203f5d7af9ead407fc0c5f55fb3 to your computer and use it in GitHub Desktop.
Save chbaranowski/5a786203f5d7af9ead407fc0c5f55fb3 to your computer and use it in GitHub Desktop.
Use Angular2 Http service outside of Angular.
export class NoXSRFStrategy extends XSRFStrategy {
configureRequest(req: Request) { }
}
// HTTP configuration to use the http service outside of angular2.
const HTTP_PROVIDERS = [
{provide: XSRFStrategy, useClass: NoXSRFStrategy},
{provide: Http, useFactory:
(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http =>
new Http(xhrBackend, requestOptions),
deps: [XHRBackend, RequestOptions]},
BrowserXhr,
{provide: RequestOptions, useClass: BaseRequestOptions},
{provide: ResponseOptions, useClass: BaseResponseOptions},
XHRBackend
];
const injector = ReflectiveInjector.resolveAndCreate([HTTP_PROVIDERS]);
const http = injector.get(Http);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment