Good morning,
I'm trying to show the objects obtained in the get request from the browser's console from angular test.service.ts:
getTestValues_Get() :Observable<Itest []>{
return this._http.get(this.url)
.map(response => <Itest[]> response.json()); }
the call from the test.component.ts component:
ngOnInit() {
this._TestService.getSettings_Get()
.subscribe(( test: ITest []) => {
this.test= test;
console.log("Array ->:" + this.test)
});}
From the WebApi returns this in ValuesController.cs.
[HttpGet]
public Setting Get()
{
using (Entities EntityDB= new Entities())
{
return EntityDB.Settings.FirstOrDefault(e=>e.TestId == 1);
}
}
When I run it I get this error:
The 'ObjectContent'1' type failed to serialize the response body for content type 'application / json
I have also added in WebApiConfig.cs:
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.Add(config.Formatters.JsonFormatter);
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
Any idea where the problem might be?
Greetings,