I’m new to Angular 4 and I’m doing my best to learn all this new stuff and for the last 2 days I’m stuck with this.
After Logging In I want to pass the API Token as a query string to my backend server with every requests.I don’t know how to achieve it. I tried using some snippets that I found on stackoverflow but those are throwing new errors. Hope someone could help me with this. Here’s my HTTP provider’s code.
import { Injectable } from '@angular/core';
import * as AppConfig from '../../app/app.config';
import {Storage} from '@ionic/storage';
import { Http, RequestOptions, URLSearchParams } from '@angular/http';
/*
Generated class for the HttpProvider provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular DI.
*/
@Injectable()
export class HttpProvider {
....
get(url:string){
let params: URLSearchParams = new URLSearchParams();
console.log(this.token);
let requestOptions = new RequestOptions();
requestOptions.search = params;
this.storage.ready().then(() => {
this.storage.get('token').then(token => {
params.set('api_token', this.token);
return this.http.get(url, requestOptions);
})
});
}
}