我正在尝试执行一个回调,其中只有在获得响应之后它才应该执行这些行,之后从this.groupDefaultExpanded = -1;
开始。
loadLoginDetails() {
this.derivativeSpecService.getDerivativeDetails().subscribe(
res => {
this.rowData = res;
this.groupDefaultExpanded = -1;
this.getDataPath = function(data) {
return data.orgHierarchy;
};
this.autoGroupColumnDef = {
headerName: "Name",
};
console.log(this.rowData);
})
}
derivativespec.ts
getDerivativeDetails(){
return this.http.get('assets/derivativespec.json').map((response: Response) => response);
}
答案 0 :(得分:1)
像这样:
getDerivativeDetails(): Promise<Response> {
return this.http.get<Response>('assets/derivativespec.json').toPromise();
}
然后:
loadLoginDetails() {
this.derivativeSpecService.getDerivativeDetails().then(
res => {
this.rowData = res;
this.groupDefaultExpanded = -1;
this.getDataPath = function(data) {
return data.orgHierarchy;
};
this.autoGroupColumnDef = {
headerName: "Name",
};
console.log(this.rowData);
});
}