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) Controllers and Scope Setting Up Our Todo App

Heatherdawn Wadleigh
Heatherdawn Wadleigh
12,301 Points

app.js errors

My app.js file so far:

angular.module("todoListApp", [])
.controller('mainCtrl', function($scope) {
  $scope.helloWorld = function() {
    console.log("Console message");
  };
});

My JSLint feedback:

1 Undeclared 'angular'.

angular.module("todoListApp", []) // Line 1, Pos 1

2 Expected '.' at column 5, not column 1.

.controller('mainCtrl', function($scope) { // Line 2, Pos 1

3 Expected one space between 'function' and '('.

.controller('mainCtrl', function($scope) { // Line 2, Pos 33

4 Expected 'use strict' before '$scope'.

$scope.helloWorld = function() { // Line 3, Pos 3

5 Expected one space between 'function' and '('.

$scope.helloWorld = function() { // Line 3, Pos 31

6 Expected 'console' at column 13, not column 5.

console.log("Console message"); // Line 4, Pos 5

7 Expected '}' at column 9, not column 3.

}; // Line 5, Pos 3

8 Expected '}' at column 5, not column 1.

}); // Line 6, Pos 1

My Markup:

      <div ng-controller="mainCtrl" class="list">

        <input type="checkbox">
        <label class="editing-label">Sample ToDo</label>
        <input class="editing-label" type="text">

        <div class="actions">
          <a class="button" href="#!">edit</a>
          <a class="button" href="#!" ng-click="helloWorld()">save</a>
          <a class="button delete" href="#!">delete</a>
        </div>

      </div><!-- /mainCtrl -->

4 Answers

jared eiseman
jared eiseman
29,023 Points

Two questions: A) Do you have your ng-app directive in your markup? B) Do you have the necessary angular script includes? (E.G. angular.min.js). Also, if I'm not mistaken JSLint requires things like angular and jquery to be declared as global variables under options if you're just trying to clear the warnings.

Heatherdawn Wadleigh
Heatherdawn Wadleigh
12,301 Points

Hi Jared,

Thanks for your reply. I do have the ng-app directive attached to the body tag. And I'm loading a minified version of angular.js in the footer (I'm combining angular.js + app.js into a minified app.min.js file). And I think I get what you're saying about the JHLint warnings (not really crucial here?)

jared eiseman
jared eiseman
29,023 Points

Are you getting any errors in the console and/or is the app not working, or are you just having lint check it out for you and are concerned about the warnings?

Heatherdawn Wadleigh
Heatherdawn Wadleigh
12,301 Points

This is my best attempt to paste what was in my console:

Error: [$injector:unpr] Unknown provider: eProvider <- e <- mainCtrl http://errors.angularjs.org/1.4.4/$injector/unpr?p0=eProvider%20%3C-%20e%20%3C-%20mainCtrl at angular.js:68 at angular.js:4284 at Object.r [as get] (angular.js:4432) at angular.js:4289 at r (angular.js:4432) at Object.i [as invoke] (angular.js:4464) at f.instance (angular.js:9093) at m (angular.js:8205) at s (angular.js:7637) at s (angular.js:7641)

jared eiseman
jared eiseman
29,023 Points

can you copy how you have the ng-app directive declared in your body tag? Better yet, your entire html file. Copying and pasting your exact code into the workspace for this video is working for me fine.

Heatherdawn Wadleigh
Heatherdawn Wadleigh
12,301 Points

OK, I did see some errors in my markup, and now it's working. Thanks for your help, that made me focus on the real problem, and find it. Cheers!

jared eiseman
jared eiseman
29,023 Points

No problem, glad to help. Happy coding!