I'm making a little site to manage recipes. I have an MVC web api server side and an angular js front end.
Now my MVC web api is serializing JSON as (clean and readable, thank you chrome plugin JSONView)
[
{
$id: "1",
Name: "Spaghetti",
CookTime: "00:30:00",
Servings: 2,
CategoryId: 1,
Category: {
$id: "2",
Name: "Pasta",
Recipes: [
{
$ref: "1"
},
{
$id: "3",
Name: "Recipe 2",
CookTime: "01:20:00",
Servings: 2,
CategoryId: 1,
Category: {
$ref: "2"
}
Id: 2
}
],
Id: 1
}
Id: 1
},
{
$ref: "3"
}
]
But on my page, I only get the first object in my list and an empty second tr tag.
Is there a way to make AngularJS understand the $ref reference? Or should I tinker with my web api config?
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(
config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"));
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.Remove(config.Formatters.XmlFormatter);
- UPDATE
The json above is a pretty representation by a chrome extension. Below is the raw data I get from my service (and formatted with JSONLint, which said it's valid JSON):
[
{
"$id": "1",
"Name": "Spaghetti",
"CookTime": "00:30:00",
"Servings": 2,
"CategoryId": 1,
"Category": {
"$id": "2",
"Name": "Pasta",
"Recipes": [
{
"$ref": "1"
},
{
"$id": "3",
"Name": "Recipe 2",
"CookTime": "01:20:00",
"Servings": 2,
"CategoryId": 1,
"Category": {
"$ref": "2"
}
"Id": 2
}
],
"Id": 1
}
"Id": 1
},
{
"$ref": "3"
}
]