Last active
August 9, 2017 22:44
-
-
Save chgc/f41b22b9a8ece38bdc5fd53950fc400c to your computer and use it in GitHub Desktop.
Play with BaseRequestOptions in Angular2
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
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 }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any chance on showing how it's used?