I have a very simple angular test app that calls $http.get('http://localhost:3001/pets')
and writes them using ngRepeat as < DIV >s into index.html
The URL returns Array with 3 objects like so:
[
{
"id": 1,
"name": "cat",
"location": "bedroom"
},
....
]
Which then get assigned using .success() to $scope.pets (Actual is Code below).
This works perfectly in all desktop browsers.
However, does nothing when I load the page on my Android using Chrome or Firefox (and IE on Nokia). There is no effect - the NodeJS/Express do not even seem to receive the request.
I tried replacing the $http.get with $.ajax (... $scope.$apply...) - code below.
I tried using services, $deffered and $q as explaned here: http://chariotsolutions.com/blog/post/angularjs-corner-using-promises-q-handle-asynchronous-calls/
When I point Chrome Mobile/Firefox directly to the API (http://localhost:3001/pets) the data is loaded into the browser with no problem. I tried hardcoding the values, like this:
$scope.pets = [{"id": 1000, "name": "GOAT", "location": "EVERYWHERE"}];
... and the do the ngClick to call $http.get and override the values.
Again, works fine on Desktop - does nothing on Mobile.
I made sure I've added the CORS headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE
Access-Control-Allow-Headers: X-Requested-With,content-type
Access-Control-Allow-Credentials: true
Why? Why would this not work on the phone browser? And I googled for 2 days....
$scope.getPets = function () {
$http.get('http://localhost:3001/pets')
.success(function(response){
//$scope.httpPets = response;
console.log('Hello, this is dog with your GET request.')
console.log(response);
})
.error(function(err){
console.log("ERROR", err)
})
.then(function(response){
console.log('Here then', response.data);
$scope.httpPets = response.data;
})
};
or this:
$scope.getPets = function(){
$.ajax('http://localhost:3001/pets').success(function(data) {
$scope.$apply(function(){ $scope.pets = data;});
console.log(data);
});
};
Thank you in advance for any suggestions.