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 Creating New Data in the UI and Saving with a Service

Christopher Johnson
Christopher Johnson
12,829 Points

How is Angular pushing to 'todos?'

The last step is to push the new todo, via

$scope.todos.push(todo);

How are we pushing to todos within the scope? I just don't understand how this line of code is getting the new todo to the mock.todos.json file.

1 Answer

Seth Kroger
Seth Kroger
56,414 Points

The push() here is Array.prototype.push which appends an item to the array. It won't change the mock todos.json file though. It will only add the todo to the array in memory.

Lorenzo Pieri
Lorenzo Pieri
19,772 Points

What Seth said is true. The pushed "todo" (which would then be part of the "todo" array) would also be saved in a backend. This course doesn't have a real backend, in fact the json file is a static file, even tho it is a json file. The real todo app would make a POST request (ideally, it could also make a GET or PUT request) to the server that commands the database.