我有一篇帖子在页面加载时发布。它返回json。然后我如何在页面上使用这个json来显示基于对象的图像和文本。
有没有办法在角度
中保存范围内对象的值我的页面加载帖子
$scope.GetData = function () {
$http({
url: "http://www.somepage.co.uk/page/page2/objects",
method: "POST",
date: {},
headers: {'Content-Type': 'application/json'}
}).then(function (response) {
// success
console.log('you have received the data ');
console.log(response);
}, function (response) { // optional
// failed
console.log('failed getting campaigns goo back to log in page.');
console.log(response);
});
};
$scope.GetData();
我想如果我可以将对象存储在不同的范围内,以便我可以在页面上使用它们。
由于
更新
这是我需要变成范围的对象
data
:
Array(1)
0
:
c_name
:
"ben"
d_text
:
[]
max_slots
:
2
resolution
:
(2) [1920, 1080]
slots
:
Array(3)
0
:
{path_image: "", base_image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…O7/aaFdrXd6na2UApSIJEwod/rWVlSUUk2h2Gbknfi6P/2Q==", slot_id: 1}
1
:
{path_image: "", base_image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…O7/aaFdrXd6na2UApSIJEwod/rWVlSUUk2h2Gbknfi6P/2Q==", slot_id: 2}
2
:
{path_image: "", base_image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…O7/aaFdrXd6na2UApSIJEwod/rWVlSUUk2h2Gbknfi6P/2Q==", slot_id: 3}
length
:
3
__proto__
:
Array(0)
__v
:
0
_id
:
"59c92d6f45b79c8c110ee6ab"
答案 0 :(得分:0)
在然后回调中,您必须将返回的数据保存到$ scope中:
$scope.GetData = function () {
$http({
url: "http://www.somepage.co.uk/page/page2/objects",
method: "POST",
date: {},
headers: {'Content-Type': 'application/json'}
}).then(function (response) {
// success
$scope.data = response; // Save the returned data into your $scope
console.log('you have received the data ');
console.log(response);
}, function (response) { // optional
// failed
console.log('failed getting campaigns goo back to log in page.');
console.log(response);
});
};