angular2-服务返回订阅中可观察到的
我有个问题。 我的服务返回一个包含更多数组的对象,我为我的页面发送navparams并订阅,但在我的页面返回observable,我不使用observable 这是怎么解决的 服务angular2-服务返回订阅中可观察到的,angular,typescript,ionic2,Angular,Typescript,Ionic2,我有个问题。 我的服务返回一个包含更多数组的对象,我为我的页面发送navparams并订阅,但在我的页面返回observable,我不使用observable 这是怎么解决的 服务 getInfoAccountById(id: any) { this.module = 'accounts/' + id + '/infos'; let headers = new Headers(); headers.append(this.key, this.token); re
getInfoAccountById(id: any) {
this.module = 'accounts/' + id + '/infos';
let headers = new Headers();
headers.append(this.key, this.token);
return this.http.get(this.url + this.module, {
headers
}).map(res => res.json().Result)
}
主页导航参数
constructor(public navCtrl: NavController, public navParams: NavParams, public acc: AccountService) {
this.navParams = navParams;
this.dataDetails = {
id: this.navParams.get('data').Id,
name: this.navParams.get('data').Identification,
complement: this.navParams.get('data').Complement,
account: this.navParams.get('data').AccountType.Identification,
pricelist: this.navParams.get('data').PriceList,
active: this.navParams.get('data').Active,
color:this.acc.getdetailsAccountById(this.navParams.get('data').Id).subscribe(data => { this.datad = data.Color; }),
informations:this.acc.getInfoAccountById(this.navParams.get('data').Id) // this line have a problem
};
}
第二页已接收参数
constructor(public navCtrl: NavController, public navParams: NavParams, public acc: AccountService, public http: Http) {
this.id = this.navParams.data.id;
this.name = this.navParams.data.name;
this.complement = this.navParams.data.complement;
this.account = this.navParams.data.account;
this.pricelist = this.navParams.data.pricelist;
this.active = this.navParams.data.active;
this.color = this.navParams.data.color;
this.infos = this.navParams.data.informations;
console.log(this.infos);
}
您只需在订阅中设置
constructor(public navCtrl: NavController, public navParams: NavParams, public acc: AccountService) {
this.navParams = navParams;
this.dataDetails = {
id: this.navParams.get('data').Id,
name: this.navParams.get('data').Identification,
complement: this.navParams.get('data').Complement,
account: this.navParams.get('data').AccountType.Identification,
pricelist: this.navParams.get('data').PriceList,
active: this.navParams.get('data').Active,
color:'',
information:''
};
this.acc.getdetailsAccountById(this.navParams.get('data').Id).subscribe(data => { this.dataDetails.color = data.Color; })
this.acc.getInfoAccountById(this.navParams.get('data').Id).subscribe(data=> this.dataDetails.information = data;
}
你是如何管理观测值的?我没有使用观测值