Skip to content

Instantly share code, notes, and snippets.

@chgc chgc/app.request.ts
Last active Aug 9, 2017

Embed
What would you like to do?
Play with BaseRequestOptions in Angular2
import { Injectable, Inject } from '@angular/core';
import { BaseRequestOptions, RequestOptions, Headers, RequestOptionsArgs } from '@angular/http';
@Injectable()
export class AppRequestOptions extends BaseRequestOptions {
constructor() {
super();
}
merge(options?:RequestOptionsArgs):RequestOptions {
let authData = localStorage.getItem('authorizationData');
let header = new Headers();
header.append('Authorization', `Bearer ${authData}`);
options.headers =header;
var result = super.merge(options);
result.merge = this.merge;
return result;
}
}
export const requestOptionsProvider = { provide: RequestOptions, useClass: AppRequestOptions };
@kahanu

This comment has been minimized.

Copy link

commented Aug 9, 2017

Any chance on showing how it's used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.