I want to get a JSON response from Flask backend to Angular app but could not find where the error is. The returning JSON response is:
{
"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."
}
]
}
And here is the controller:
function Phones($scope, $http){
$http.get('127.0.0.1:5000/phones').success(function(data){
$scope.phns = data.phones;
console.log("I'm called");
});
}
This works when I pass the JSON object to the controller like this:
$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}
];
It also doesn't work when I try to get data like data.phones. I'm sure the controller gets called but the get function does not get the data somehow.