I am trying to do a simple todo app with RESTful api. My restful service returns the below JSON,
[{"title":"completed this","completed":false},{"title":"and this too","completed":false}]
Returned as a application/json not a string.
My view is as below,
<div class="container" ng-app="todomvc">
<div id="todoapp" ng-controller="TodoCtrl">
<div class="row" ng-repeat="todo in todos">
{{todo.title}}
</div>
</div>
</div>
And I have the below JS code with controller and a factory,
var todomvc = angular.module('todomvc', []);
todomvc.factory('todoREST', function ($q,$http) {
function get(){
return $http.get('http://localhost/test.php');
}
return{get:get};
});
todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, $filter, todoREST) {
var todos = $scope.todos = todoREST.get().then(function(data){
todos = data.data;
console.log(todos); // Data available here
});
});
I am unable to get the title in the page when it is loaded. What am I doing wrong? And is my approach the right way to make a RESTful call?
Here is a link to what I have done, http://plnkr.co/edit/kaSCe9HoMPEK1hD4QgJl?p=preview