我可能使用标头作为服务器URL,并且在组件之一中声明了标头,并且我想在所有有服务器调用但无法订阅该标头的组件中使用该标头,任何人都可以帮助我
我的界面组件
import { Injectable } from '@angular/core';
@Injectable()
export class Config {
header = 'http://localhost/a2server/index.php/';
}
我的main.ts(在这里我想使用标题)
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)
我知道我错了,有人可以帮我吗
可注射的
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];
});
}
}
您订阅了可观察的东西。对于一个简单的字符串,您只需访问该属性:
var data :any;
constructor(public location: Location,public config:Config,public router: Router, public http: Http, fbld: FormBuilder,public toastr: ToastsManager) {
console.log(this.config.header);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句