am struggling to figure out, what's wrong with my code. I'm trying to call a rest API from my angular code, but it results in "TypeError: Cannot read property 'id' of undefined"
My clients.ervice.ts code looks like this:
import { Injectable } from '@angular/core';
import { Clients } from './clients.model';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ClientsService {
clientsUrl="http://localhost:21063/api/clints
constructor(private http:HttpClient) { }
getAllClients():Observable<Clients[]>{
return this.http.get<Clients[]>(this.clientsUrl);
}
My code in the client.component.ts
constructor(private formBuilder: FormBuilder, private Service: ClientsService) { }
clients:Clients[];
ngOnInit() {
this.Service.getAllClients()
.subscribe(data => this.clients=data);
and this is model.ts
export class Clients {
id:number;
name:string;
phone:string;
address:string;
type:string;
account:number;
nots:string;
branchId:number;
}
finaly my templets:
<tbody>
<tr *ngFor="let item of clients"></tr>
<td>{{item.id}} </td>
<td>{{item.name}} </td>
<td>{{item.phone}} </td>
<td>{{item.address}} </td>
<td>{{item.account}} </td>
<td>{{item.nots}} </td>
</tbody>
thanks in advance for any help to fix and understand this problem