I am learning Angular but I am stuck trying to use the $http service and a JSON array. I have an array called names. I can show its content inside the function, but outside it shows this error: TypeError: Cannot read property 'Name' of undefined. I think the array is not beeing modified properly. But I don't know why. I took my code from an example from W3shools.com (http://www.w3schools.com/angular/tryit.asp?filename=try_ng_customers_json). I modified it a little bit. Why when I want to show the content of the name variable the second time I get the error?
var names = [];
$http.get("http://www.w3schools.com/angular/customers.php")
.success(function(response) {
names = response.records;
console.log("The name is: " + names[0].Name);
});
console.log("And now the name again: " + names[0].Name);