Hi I have a simple controller that returns a simple (I’ve simplified it all for this post):
[HttpGet("[action]")]
public AppSettings GetStuff()
{
var stuff = new Stuff { Dummy = ”Hi”; };
return stuff;
}
public class Stuff
{
public string Dummy { get; set; }
}
All good, now I call it from my Angular service:
getStuff(): Observable<IStuff> {
return (this.httpClient
.get<IStuff>(this.localUrl)
.pipe(
catchError(this.errorHandlerSerevice.handleError)
)) as any;
}
Here’s my IStuff:
export interface IStuff {
Dummy?: string;
}
All good… The console shows me 200 and the response…
But when I subscribe to getStuff() from my component I get [object object] or udentified… I have tried a god few subscriptions but no luck:
stuff: IStuff;
getStuff(){
this.stuffService.getStuff()
.subscribe(stuff => this.stuff = stuff);
}
Or:
getStuff(){
this.stuffService.getStuff()
.subscribe((data: IStuff) => this.stuff = {
Dummy: data['Dummy']
});
}
Any idea?
[object object] or udentified? On the console? Where exactly did you log the response?alertwill calltoString()on your object, which will result in[Object object]. If you want the JSON format, you'll need to callJSON.stringifyyourself