Issue
I have following method in typescript, I need to bind to angular grid
CountryService
GetCountries() {
return this.http.get(`http://services.groupkt.com/country/get/all`)
.map((res:Response) => <CountryData[]>res.json().RestResponse["result"]);
}
GridComponent
template: `
<ag-grid-ng2 style="width: 100%" #agGrid class="ag-material"
rowHeight="50"
[gridOptions]="myGridOptions"
>
</ag-grid-ng2>
`,
this.myGridOptions.rowData= this.CountryService.GetCountries();
CountryData
export class CountryData{
name: string;
alpha2_code: string;
alpha3_code: string;
}
But GetCoutries will return Observable of any, unable to bind to rowData?
How to convert Observable to CountryData[] in typescript ?
you find JSON data here: http://services.groupkt.com/country/get/all
Solution
You will need to subscribe to your observables:
this.CountryService.GetCountries()
.subscribe(countries => {
this.myGridOptions.rowData = countries as CountryData[]
})
And, in your html, wherever needed, you can pass the async
pipe to it.
Answered By - CozyAzure
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.