我有以下方法,
public getResults(page: Page ): Observable<PagedData<CorporateEmployee>> {
var companyData1:Observable<PagedData<CorporateEmployee>>;
this.getUsersData().subscribe(users=>{
//companyData1.push(users['info']);
alert('local func2');
companyData1 = Observable.of(users['info']).map(data => this.getPagedData(page,users['info']));
});
alert('local func1');
//alert(this.companyData);
return companyData1;
// this.getUsers();
}
还有一个db值的方法,
getUsersData():Observable<any[]>{
alert('called func');
return this._http.get(this._productUrl+'get_users_data',this.header)
.map((response:Response)=><any[]>response.json())
.do(data=>{console.log(data['info']);this.companyData = data['info'];})
.catch(this.handleError);
}
在这里,还有什么不对。我无法将其分配给类变量。我想订阅我的类变量的json响应。即使我指定,它也没有任何东西。警告该变量,它显示'未定义'。
答案 0 :(得分:0)
订阅做这样的事情:
ngOnInit() {
console.log(this._userService)
this._userService.getUsersData().subscribe(data => {
this.d = data;
}, error => console.log(error));
服务:
public getUsersData():Observable<any[]>{
return this._http.get('response.json')
.do(data=>{
this.x = data;
console.log(data);
})
.catch(this.handleError);
}