我想从 Flask 后端获取到 Angular 应用程序的 JSON 响应,但找不到错误所在。返回的 JSON 响应是:
{
"phones": [
{
"age": 0,
"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S."
},
{
"age": 1,
"name": "Motorola XOOM with Wi-Fi",
"snippet": "The Next, Next Generation tablet."
},
{
"age": 2,
"name": "MOTOROLA XOOM",
"snippet": "The Next, Next Generation tablet."
}
]
}
这是控制器:
function Phones($scope, $http){
$http.get('127.0.0.1:5000/phones').success(function(data){
$scope.phns = data.phones;
console.log("I'm called");
});
}
当我像这样将 JSON 对象传递给控制器时,这有效:
$scope.phones = [
{"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S.",
"age": 0},
{"name": "Motorola XOOM with Wi-Fi",
"snippet": "The Next, Next Generation tablet.",
"age": 1},
{"name": "MOTOROLA XOOM",
"snippet": "The Next, Next Generation tablet.",
"age": 2}
];
当我尝试获取 data.phones 之类的数据时,它也不起作用。我确定控制器会被调用,但 get 函数不会以某种方式获取数据。