I used the code given in this site to create a datatable. the url is:https://stackblitz.com/angular/dnbermjydavk?file=app%2Ftable-overview-example.html
in this code the data to be displayed in the table is hardcoded, but i wanted to display a json data which is fetched from a api.
I had already created a service component for fetching the data from api, but i am feeling difficulty in implementing this json data inside datatable.
How to use it inside the data table to display all the json data.
my service component
</
bloghttpservice.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpClientModule } from
'@angular/common/http';
import { HttpErrorResponse, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Observable'
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
@Injectable({
providedIn: 'root'
})
export class BankhttpService {
private baseUrl = "https://vast-shore-74260.herokuapp.com/banks";
public myCity = "MUMBAI"
constructor(private _http : HttpClient) {
console.log('Bank http service called');
}
private handleError(err:HttpErrorResponse){
console.log('Handle http error');
console.log(err.message);
return Observable.throw(err.message);
}
public getBankBranches(): any {
let myResponse = this._http.get(this.baseUrl + '?city=' + this.myCity);
console.log(myResponse);
return myResponse;
}
}
/>