My user
data is causing some issues and looks like this...
[{"firstName":"Pinkie","lastName":"Connelly","username":"Darlene.Marvin","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="19506a767b7c75464b7c77777c6b5971766d74787075377a7674">[email protected]</a>"},{"firstName":"Easter","lastName":"Ruecker","username":"Giovani.Collier59","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e6a78888878b8783d3d2a6818b878f8ac885898b">[email protected]</a>"},{"firstName":"Harmon","lastName":"Luettgen","username":"Rosanna51","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0b466478636e32334b726a63646425686466">[email protected]</a>"},{"firstName":"Angeline","lastName":"Kunze","username":"Gabriel_Braun69","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6923080a021a06075b582901061d04080005470a0604">[email protected]</a>"},{"firstName":"Gayle","lastName":"Bahringer","username":"Dorcas_Roob55","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ecab9e89959f8382d5daac8b818d8580c28f8381">[email protected]</a>"},{"firstName":"Adriana","lastName":"Renner","username":"Serenity.Armstrong42","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cd9ea4a0e39fa2afa8a18daaa0aca4a1e3aea2a0">[email protected]</a>"},{"firstName":"Arvid","lastName":"Kiehn","username":"Estrella87","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="246e455d48454a7b694b564d5757415050411314645d454c4b4b0a474b49">[email protected]</a>"},{"firstName":"Kristofer","lastName":"Nader","username":"Terence.Walker7","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abe9d9cacfd29292ebc3c4dfc6cac2c785c8c4c6">[email protected]</a>"},{"firstName":"Rosa","lastName":"Lebsack","username":"Freida_Hegmann46","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="27664b464949467874444f4a4e53531f1e1e674f48534a464e4b0944484a">[email protected]</a>"},{"firstName":"Rogers","lastName":"Thiel","username":"Mike_Braun","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="18597f767d6b364b70717d747c6b2b587f75797174367b7775">[email protected]</a>"}]
I am using Angular and have imported Material Angular. Initially, I faced a challenge with using *NgFor
with this data structure. But since Angular V6, you can now utilize a keyValue
pipe which is quite convenient!
Next, I attempted to use *NgFor within a table to populate rows for each person. However, instead of NgFor, tables require the usage of dataSource:
<table mat-table #table [dataSource]="user">
<!-- table rows -->
</table>
Nevertheless, I encountered an error stating:
Provided data source did not match an array, Observable, or DataSource at getTableUnknownDataSourceError
This is how I am fetching the user
data -
export class AppComponent {
error: any;
title = 'toms-app';
user: User;
constructor(private apiServicefile: ApiServicefile) { }
ngOnInit(): void {
this.apiServicefile.getUser()
.subscribe(
(data: User) => this.user = { ...data }, // success path
error => this.error = error // error path
);
}
}
I am new to TypeScript and would appreciate some guidance on achieving my desired outcome. Can someone please assist?