I've set up a header for my server URL in one of the components, and I want to use this header in all components whenever there is a server call. However, I am having trouble subscribing to this header. Can someone please assist me?
Interface component:
import { Injectable } from '@angular/core';
@Injectable()
export class Config {
header = 'http://localhost/a2server/index.php/';
}
Main.ts (where I want to use the header):
var data: any;
constructor(public location: Location, public config: Config, public router: Router, public http: Http, fbld: FormBuilder, public toastr: ToastsManager) {
this.config
.subscribe(header => this.data = data);
console.log(this.data)
I realize I may be doing something wrong. Can someone please guide me?
Injectable:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Component } from '@angular/core';
import { IDetails } from './details';
import { Config } from '../headers';
@Component({
providers: [Config]
})
@Injectable()
export class GetCustInfo {
header: any;
str = localStorage.getItem('social');
loc = JSON.parse(this.str);
id = this.loc.profile_id;
constructor(private _http: Http, public config: Config) { this.header = this.config.header;}
private _productUrl = this.header + 'profile/editcustominfo/' + this.id;
getCustList(): Observable<IDetails[]> {
return this._http.get(this._productUrl)
.map((response: Response) => {
return <IDetails[]> response.json().data[0];
});
}
}