I am implementing Angular template for reading .CSV file and generating table. So I created two .CSV file, one for the header and second one for the table content.
For heading CSV file: header.csv
For data of table CSV file: tableContent.csv
Now I am able to read all data and converted into array, But I am getting into one array. I am sharing my code for more understanding.I have putted .csv file in assets folder.
app.component.ts
export class AppComponent {
title = 'project';
myData: any;
myContent: any;
constructor(private httpClient: HttpClient) { }
ngOnInit() {
this.httpClient.get('assets/header.csv', { responseType: 'text' }).subscribe(
data => {
this.myData = data.split("\n");
}
);
}
clicked(event) {
console.log(event.srcElement.name);
this.httpClient.get('assets/tableContent.csv', { responseType: 'text' }).subscribe(
data => {
this.myContent = data.split(",");
let ab=this.myContent;
console.log("------------>",ab);
}
);
}
}
app.component.html
<table id="customers">
<tr>
<th *ngFor="let dataheader of myData"><button (click)="clicked($event)" id={{dataheader}} name={{dataheader}}>{{dataheader}}</button></th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
<td>Germany</td>
</tr>
</table>
I want to create multiple object of array. like below:
[{
"myAccess":["myAccess","Prod","URL","[email protected]","Enable"]
},
{
"System":["System","Environment","URL","[email protected]","Enable"]
},
{
"OAM":["OAM","DEV","URL","[email protected]","Enable"]
},
{
"Mylogin":["Mylogin","prod","URL","[email protected]","Enable"]
}]
Table heading will comes from particular header.csv and data will comes from tableContent.csv. So Finally If i will click on the particular header so It will search into json object(which is read by tablecontent.csv). will show the particular result. Like if I will click on the myAccess so related myaccess data show in the table data.
Thanks in advance, Kindly share your idea.



