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

Talha Khalid
Talha Khalid
10,262 Points

Error Message with Angular

Hello All, I keep getting a "SyntaxError: Unexpected token ' " at angular.min.js: 28460. Can someone help me figure out if this is an issue with my code or something with angular?

angular.module("todoListApp",[]) //name of app and definitions of dependeices. Empty tells angular to create file. If 2nd arg left off. will look for totdolist app instead of creating it. 

.controller('mainCtrl',function ($scope,dataService){
    $scope.helloService = dataService.helloLog();
    $scope.helloWorld = function (){
        console.log("Hello World, this is the main cotnroller speaking!");
    $scope.whatsgoodWorld = function ($scope) {
        console.log("Whats good world?!");

  $scope.learningngchange = function (){
    console.log("An Input Changed");

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

})//Name and call back function

.service("dataService", function($http){
    this.helloLog = function(){
        console.log("Hello, this is my first service!");
      };// this attaches method to service

  this.getTodos = function (callback){$http.get('mock/todos.json')
     } //1st arg to get is url to filepath. 'then' executes after response from server
Kristopher Van Sant
Kristopher Van Sant
Courses Plus Student 18,830 Points

Hey there, I reformatted your code so that it's easier to read. :)

3 Answers

Mike Patterson
Mike Patterson
5,521 Points

Try using double quotes(") instead of single quotes(') in your .json file

I had this same issue, make sure in your json file that the last comma is removed:

    {"name": "Clean the house"},
    {"name": "Water the dog"},
    {"name": "Feed the lawn"},
    {"name": "Pay bills"},
    {"name": "Run"},
    {"name": "Swim"}
Jack Blankenship
.a{fill-rule:evenodd;}techdegree seal-36
Jack Blankenship
Full Stack JavaScript Techdegree Graduate 39,036 Points

I would remove the single quotes from around 'then' to see if that is the cause of your problem. The other issue could be you have terminated your getTodos function with a } instead of };