I am developing a small Angular application that aims to list bank accounts, and to be able to manipulate them with CRUD (there are also transactions). But here’s a problem for me, and I really don’t understand why. When I click on one of the listed accounts, it sends me to another page containing the account details (Balance, Name,...), I have however well set up (at least I assume) the Get(id), with it I get an object that then allows me to manipulate the data. But it doesn’t work and I always get the same mistake as here:
There is my Account Service (the Get(id) i use HttpClient) :
public getCompte(id: number): Observable<Compte> {
return this.http.get<Compte>('http://localhost:33713/api/Compte/' + id);
}
There is my Account class :
export class Compte {
private _Id: number;
private _Nom: string;
private _Solde: number;
private _AllowsDecouvert: boolean;
constructor(Nom?: string, Montant?: number, Decouvert?: boolean) {
this._Nom = Nom;
this._Solde = Montant;
this._AllowsDecouvert = Decouvert;
}
get Id(): number {
return this._Id;
}
set Id(value: number) {
this._Id = value;
}
get Nom(): string {
return this._Nom;
}
set Nom(value: string) {
this._Nom = value;
}
get Solde(): number {
return this._Solde;
}
set Solde(value: number) {
this._Solde = value;
}
get AllowsDecouvert(): boolean {
return this._AllowsDecouvert;
}
set AllowsDecouvert(value: boolean) {
this._AllowsDecouvert = value;
}
public static fromJSON(rawCompte: any) : Compte {
const tmpCompte = new Compte(rawCompte['Nom'], rawCompte['Montant'], rawCompte['Decouvert']);
tmpCompte.Id = rawCompte['Id'];
return tmpCompte;
}
public static fromArrayJSON(rawComptes: any[]) : Compte[] {
return rawComptes.map(Compte.fromJSON);
}
public getCleanDataForSending() {
return {
"Id": this.Id,
"Nom": this.Nom,
"Montant": this.Solde,
"Decouvert": this.AllowsDecouvert
};
}
}
And there is my component code :
export class DetailsComponent implements OnInit {
public detail$: Compte ;
private id;
constructor(private route: ActivatedRoute, private _cmptService: CompteService) {
this.route.params.subscribe( params => this.id = params.id );
}
ngOnInit() {
this._cmptService.getCompte(this.id).subscribe(
res => { this.detail$ = Compte.fromJSON(res); }
);
Thank in advance ;)