Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Gavin Murphy
Gavin Murphy
10,004 Points

Problem pulling json file

Ng-repeat is working here on my mark up

angular.module("todoListApp", []) .controller("mainCtrl",function($scope, dataService){ $scope.todos = [
{"name": "clean the shop"},
{"name": "finish angular app"}, {"name": "update css"}, {"name": "finish thank you page"}, {"name": "make queriy calculator responsive"}, {"name": "clean urls"} ]; })

But here it is not working when the array is in a json file

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

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

    });

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

PLEASE HELP!

Yosef VanTine
Yosef VanTine
8,880 Points

please re-format your code properly so we can read it easier

Milan Nikolic
Milan Nikolic
24,365 Points

change url of geting files with this... this.getTodos = $http.get('scripts/mock/todos.json')

reading files is starting from index.html not from app.js