Created
January 21, 2017 21:30
-
-
Save chbaranowski/5a786203f5d7af9ead407fc0c5f55fb3 to your computer and use it in GitHub Desktop.
Use Angular2 Http service outside of Angular.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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