We need to make some changes in order to test our code on Android. We also need to make changes to the endpoint that we are calling; http://localhost:8000
will need to be changed to http://10.0.2.2
.
For this Android version, your js/services/todo.js
will look as follows:
angular.module('todoApp.services',[]) .config(function ($httpProvider){ $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; }) .factory('Todos', function($http) { return { getAll: function () { return $http.get('http://10.0.2.2:8000/todos'); // if using android //return $http.get('http://localhost:8000/todos'); }, getTodo: function (id) { return $http.get('http://10.0.2.2:8000/todos?id='+id); // if using android //return $http.get('http://localhost:8000/todos?id='+id); }, save: function (todoData) { return $http.post('http://10.0.2.2:8000/todos', todoData); // if using android ...