I've been working on this for hours without success.
I created a web API get method that returns a simple array.
public Hero[] getHeroes()
{
return new Hero[] { new Hero { Id = 1, Name = "Hunain Hafeez-1" },
new Hero {Id= 2, Name = "Hunain Hafeez-2" }
};
}
and
[HttpGet]
[EnableCors(origins: "*", headers: "*", methods: "*")]
public IEnumerable<Models.Hero> GetHeroes()
{
LocalHeroes= heroes.getHeroes();
return LocalHeroes;
}
now in angular
service.ts
getHeroesFromWebAPI(): Observable<any>
{
return of(this.http.get<any>("https://localhost:44320/api/values").subscribe(res => JSON.stringify(res)));
}
in component.ts
getHeroes(): void
{
this.heroService.getHeroesFromWebAPI().subscribe( r => {this.HeroesWebAPI= r;
console.log("STRINGFIED:"+ this.HeroesWebAPI)});
}
and whereas
HeroesWebAPI: any[]= [];
In the component's getHeroes
method, the this.HeroesWebAPI
displays as Object Object
and when I attempt to stringify
it, I receive a
CANNOT CONVERT CIRCULAR STRUCTURE TO JSON
error.
What is the solution to this issue?