Skip to content

Instantly share code, notes, and snippets.

@cchng
Created August 15, 2018 05:50
Show Gist options
  • Save cchng/eb2a0e054db45f1a7abbb7fa50b47603 to your computer and use it in GitHub Desktop.
Save cchng/eb2a0e054db45f1a7abbb7fa50b47603 to your computer and use it in GitHub Desktop.
display a table with angular grid
import { Component, OnDestroy, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { AgGridModule } from 'ag-grid-angular';
@Component({
templateUrl: 'myobject.component.html'
})
export class MyObjectComponent implements OnInit {
title = 'app';
columnDefs = [
{headerName: 'Object Name', field: 'object_name' },
{headerName: 'Object Field 1', field: 'object_field_1' },
];
rowData: any;
constructor(private http: HttpClient) {
}
ngOnInit() {
// api returns json containing data with columnDef fields as keys
// TODO: figure out how to get nested data
this.rowData = this.http.get('http://localhost:3000/api/myobject');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment