-
-
Save paritosh64ce/9e4fbd8de38853534b36227be4d003c6 to your computer and use it in GitHub Desktop.
See how Observable.flatMap makes the world a better place to code! compare this with https://gist.github.com/paritosh64ce/917e70f43e7d160a27b00f36491b87c0
This file contains 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 { Http, Headers, RequestOptions } from '@angular/http'; | |
import { Observable } from 'rxjs/Observable'; | |
@Injectable() | |
export class myHTTPSvc { | |
constructor(private http: Http, private upSvc: MyUserProfileService) {} | |
get(url) : Observable<any> { | |
this.upSvc.getLoggedInUserDetails() | |
.flatMap(details => { | |
let headerConfig = this.getHeaderConfig(details); | |
return this.http.get(url, headerConfig) | |
.map(data => data.json()); | |
}); | |
} | |
private getHeaderConfig(loggedInUserDetails: any): RequestOptions { | |
let options = new RequestOptions(); | |
options.headers = new Headers(); | |
options.headers.append('license', loggedInUserDetails.licenseInfo); | |
// or any details you want to push in message header | |
return options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment