我有来自后端的这种响应格式(URL为http://localhost:8080/App/api/currency):
{
"content": [
{
"code": "CHF",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/CHF"
}
]
},
{
"code": "EUR",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/EUR"
}
]
},
{
"code": "USD",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/USD"
}
]
},
{
"code": "AUD",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/AUD"
}
]
},
{
"code": "CAD",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/CAD"
}
]
},
{
"code": "GBP",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/GBP"
}
]
},
{
"code": "NZD",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/NZD"
}
]
},
{
"code": "JPY",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/JPY"
}
]
},
{
"code": "SEK",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/SEK"
}
]
},
{
"code": "NOK",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/NOK"
}
]
},
{
"code": "ISK",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/ISK"
}
]
},
{
"code": "DKK",
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency/DKK"
}
]
}
],
"_links": [
{
"rel": "self",
"href": "http://localhost:8080/App/api/currency"
}
]
}
要使用Angular查询它我使用$resource's
查询方法。但是这种响应结构不适用于$resource
:
如何使此回复与$resource
一起使用,即指示它将content
作为构建$resource
对象的实际数据。或者有任何可靠的解决方案吗?
答案 0 :(得分:0)
一种方法是明确使用<div class="content-section-b">
<div class="row">
<div class="col-lg-12">...
:
$promise
当然,以这种方式使用return $resource(url).get().$promise.then(function(response){
return response.content;
});
时,$resource
与$http
没有太大区别,使用$resource
优于$http
的优势,就像直接使用{{1}}一样将结果绑定到范围,将丢失。