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

Joe Hochgreve
PLUS
Joe Hochgreve
Courses Plus Student 2,110 Points

ng-repeat not working for me.

I am following along with the video and have copy/pasted the array (along with tried my own), but in the workspaces preview the data is not rendering as to-dos. The screen flashes for a second before all to-dos vanish....what am I doing wrong.

Here is my html:

<!doctype html> <html lang="en"> <head> <title></title> <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'> <link href='styles/main.css' rel='stylesheet' type="text/css"> </head> <body ng-app="todoListApp"> <h1>My TODO'S</h1> <div ng-repeat="todo in todos"> <div class="list"> <input ng-model="todo.checked" type="checkbox" /> <label ng-hide="editing" class="editing-label">{{todo.name}}</label> <input ng-model="todo.name" ng-show="editing" type="text" class="editing-label"/> </div> <div class="actions"> <a href="" ng-click=" editing = !editing">edit</a> <a href="" ng-click="helloWorld()">save</a> <a href="" class="delete">delete</a> </div> </div> {{todo}} <script src="vendor/angular.js" type="text/javascript"></script> <script src="scripts/app.js" type="text/javascript"></script> </body> </html>

Here is my JavaScript:

angular.module("todoListApp", []) .controller('mainCtrl', function($scope){ $scope.helloWorld = function(){ console.log('This is some cool shit! AND you just clicked my button bitch!'); };

$scope.todos = [
  {"name": "clean the house"},
  {"name": "water the dog"},
  {"name": "feed the lawn"},
  {"name": "pay dem bills"},
  {"name": "run"},
  {"name": "swim"}
];

});

2 Answers

Kevin Garibo
Kevin Garibo
4,800 Points

Hi Joe... Probably your code isn't working because there is a missing directive (ng-controller='mainCtrl'), I tried this and it worked for me.

The HTML File:

<!doctype html>
<html lang="en" ng-app="todoListApp"> 
    <head> 
        <title></title> 
        <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'> 
        <link href='styles/main.css' rel='stylesheet' type="text/css">
    </head> 
    <body ng-controller="mainCtrl"> 
        <h1>My TODO'S</h1> 
        <div ng-repeat="todo in todos"> 
            <div class="list"> 
                <input ng-model="todo.checked" type="checkbox" /> 
                <label ng-hide="editing" class="editing-label">{{todo.name}}</label> 
                <input ng-model="todo.name" ng-show="editing" type="text" class="editing-label"/> 
            </div> 
            <div class="actions"> 
                <a href="" ng-click=" editing = !editing">edit</a> 
                <a href="" ng-click="helloWorld()">save</a> 
                <a href="" class="delete">delete</a> 
            </div> 
        </div> {{todo}} 
        <script src="vendor/angular.js" type="text/javascript"></script> 
        <script src="scripts/app.js" type="text/javascript"></script>
    </body> 
</html>

The JS File:

angular.module("todoListApp", []) 
.controller('mainCtrl', function($scope){ 
    $scope.helloWorld = function(){ 
        console.log('This is some cool shit! AND you just clicked my button bitch!'); 
    };
    $scope.todos = [
      {"name": "clean the house"},
      {"name": "water the dog"},
      {"name": "feed the lawn"},
      {"name": "pay dem bills"},
      {"name": "run"},
      {"name": "swim"}];
});
Joe Hochgreve
PLUS
Joe Hochgreve
Courses Plus Student 2,110 Points

Well that makes sense. Hmmmm looks like he never actually added that in the video's. Was following along.