【发布时间】:2016-07-23 13:23:13
【问题描述】:
我正在尝试使用rxjs 在Angular 中打印http 调用的结果
考虑下面的代码
import { Component, Injectable, OnInit } from '@angular/core';
import { Http, HTTP_PROVIDERS } from '@angular/http';
import 'rxjs/Rx';
@Injectable()
class myHTTPService {
constructor(private http: Http) {}
configEndPoint: string = '/my_url/get_config';
getConfig() {
return this.http
.get(this.configEndPoint)
.map(res => res.json());
}
}
@Component({
selector: 'my-app',
templateUrl: './myTemplate',
providers: [HTTP_PROVIDERS, myHTTPService],
})
export class AppComponent implements OnInit {
constructor(private myService: myHTTPService) { }
ngOnInit() {
console.log(this.myService.getConfig());
}
}
每当我尝试打印出getconfig 的结果时,它总是返回
Observable {_isScalar: false, source: Observable, operator: MapOperator}
即使我返回一个 json 对象。
如何打印getConfig 的结果?
【问题讨论】:
-
你找到解决方案了吗?
标签: typescript angular reactive-programming rxjs observable