I have the following typescript model:
export class ClaimProvider {
id: string;
name: string;
slug(): string {
let result = this.name.trim().toLowerCase();
result = result.toLowerCase();
result = result.replace(/&/g, '_');
result = result.replace(/ /g, '_');
return result;
}
}
Now in my Angular component I get an API call that populates a local instance of my object:
claimprovider: ClaimProvider;
this.claimProviderService.getCurrentClaimProvider(id)
.pipe(first())
.subscribe(
result => {
this.claimprovider = result;
console.log(this.claimprovider);
}
}
My console.log results show the name and id appropriately so my API call is working.
My problem though is if in the same point I call:
console.log(this.claimprovider.slug())
Then I get an error
ERROR TypeError: _this.claimprovider.slug is not a function
What am I doing wrong?
Edit
This is my getCurrentClaimProvider method:
public getCurrentClaimProvider(claimproviderId): Observable<ClaimProvider> {
return this.http.get<ClaimProvider>(this.baseUrl + '/GetCurrentClaimProviderHeader?claimproviderid=' + claimproviderId);
}