Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS Basics (1.x) Services in Angular Using Services To Get Data

Alessandro Muraro
Alessandro Muraro
15,457 Points

All my todos are gone

I'm trying to follow along, and it seems to me all has been followed correctly, but clearly I must be missing something.

Right now, I see no todo items, although the ng-repeat is working

My code is as follows:

angular.module("todoListApp", [])
  .controller('mainController', function($scope, dataService){

    dataService.getTodos(function(response){
        console.log(response.data);
        $scope.todos = response;
    });

  })
  .service('dataService', function($http) {
    this.getTodos = function(callback){
        $http.get('js/mock/todos.json')
        .then(callback)
    }
  })
;

My todo list shows five empty rows.

Any help is appreciated, thanks!

2 Answers

HI

Try adding .data to the response your assigning to $scope.todos

dataService.getTodos(function(response){
        console.log(response.data);
        $scope.todos = response.data;
    });

That should probably fix it.