我试图打印的结果 http
调用在 Angular
使用 rxjs
考虑以下代码
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());
}
}
Whenever I tried to print out the result of getconfig
it always return
Observable {_isScalar: false, source: Observable, operator: MapOperator}
即使我返回了一个 json 对象。
如何打印 getConfig
的结果?