Skip to content

Instantly share code, notes, and snippets.

@chgc
Last active August 9, 2017 22:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chgc/f41b22b9a8ece38bdc5fd53950fc400c to your computer and use it in GitHub Desktop.
Save chgc/f41b22b9a8ece38bdc5fd53950fc400c to your computer and use it in GitHub Desktop.
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
Copy link

kahanu 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