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

Ze Yang
Ze Yang
495 Points

Callback is not defined

This is my code. When I run, it shows an error "callback is not defined" ```angular.module("todoListApp", []) .controller('mainCtrl', function ($scope, dataService) {

    $scope.learningNgChange = function () {
        console.log("An input changed");
    };
    $scope.helloConsole = dataService.helloConsole;
    dataService.getTodos(function (response) {
        console.log(response.data);
        $scope.todos=response.data;
    });
})
.service('dataService', function ($http) {
    this.helloConsole = function () {
        console.log("This is hello servie")
    };
    this.getTodos = function () {
        $http.get('mock/todos.json')
    .then(callback)
    }
});

1 Answer

Steven Parker
Steven Parker
229,980 Points

The last line of code is: .then(callback), but there is no function named "callback" in this module. Did you forget to include another module where it is defined? Or is that just a placeholder name, and you forgot to replace it with a (possibly anonymous) function to serve as a callback?

Ze Yang
Ze Yang
495 Points

Thanks Steven! I forget to name the function. It works, if I change it to:

this.getTodos = function (callback)