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 trialTalha Khalid
10,262 PointsError 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')
.then(callback)
} //1st arg to get is url to filepath. 'then' executes after response from server
});
3 Answers
Mike Patterson
5,521 PointsTry using double quotes(") instead of single quotes(') in your .json file
Damian Smith
8,045 PointsI 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
Full Stack JavaScript Techdegree Graduate 39,036 PointsI 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 };
Kristopher Van Sant
Courses Plus Student 18,830 PointsKristopher Van Sant
Courses Plus Student 18,830 PointsHey there, I reformatted your code so that it's easier to read. :)