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 trialJonathan Martínez
13,375 PointsFIX: Save button not working when clicked!
In case you are having a hard time trying to understand why the ng-controller is not working when the save button is clicked, is because seems that Huston made changes to the original template without telling you.
In order for the save button to work, it must be inside the scope of the controller.
This is the original template as we were following the video:
<div ng-controller="mainCtrl" class="list">
<input type="checkbox">
<label class="editing-label" for="">A sample Todo!</label>
<input class="editing-label" type="text">
</div>
<div class="actions">
<a href="">edit</a>
<a ng-click="helloWorld()" href="">save</a>
<a class="delete" href="">delete</a>
</div>
See that the controller is only scoped to the div with the list class, and it's not including the div with actions class (where the save button is); so it won't work because is out of the reach of the controller.
The fix is pretty easy, just move the div with actions class inside the list div like this:
<div ng-controller="mainCtrl" class="list">
<input type="checkbox">
<label class="editing-label" for="">A sample Todo!</label>
<input class="editing-label" type="text">
<div class="actions">
<a href="">edit</a>
<a ng-click="helloWorld()" href="">save</a>
<a class="delete" href="">delete</a>
</div>
</div>
This way, the button will work because it is withing the reach/scope of the controller!
Anthony Domina
Courses Plus Student 19,571 PointsWas banging my head against the wall. This was the exact thing I needed!
Dwayne Pate
12,249 PointsThanks. Completely missing that the div was closed!
Marcus Thelin
1,188 PointsThank you!!
Krystal Smith-Moore
4,881 PointsKrystal Smith-Moore
4,881 PointsAwesome thank you for the info because I would have struggled with this.