I am new to angular and I have been trying to use the http
module to fetch data from my backend. In my user.component.html
file, I have the following code:
<tr *ngFor="let item of transporter.liste">
<td>{{item.name}}</td>
<td>{{item.prenom}}</td>
<td>{{item.name}}</td>
My service looks like this:
getList():Observable<Transporter>{
return this.http.get<Transporter>("http://localhost:9000/users/list")
.pipe(
tap(transporter=>console.log(transporter))
);
Additionally, I have defined a class:
export class Transporter{
error: string;
success: string;
liste: [];
objet: {};
constructor(error:string, success:string,liste:[],objet:{}){
this.error=error;
this.success=success;
this.liste=liste;
this.objet=objet;
}
}
Finally, here is the users component:
export class UsersComponent implements OnInit {
transporter:any;
constructor(private userService: UserService) {
}
ngOnInit(): void {
this.onGetUsers();
console.log(this.transporter);
}
onGetUsers():void{
this.userService.getList()
.subscribe(
(response)=>{this.transporter=response; },
(error)=>console.log(error),
()=>console.log("Done")
);
}
}
I would appreciate any help in understanding what might be going wrong.