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) Improving Our Todo App Finalizing Our Application

Andrea Miotto
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andrea Miotto
iOS Development Techdegree Graduate 23,357 Points

TypeError: Cannot assign to read only property 'edited' of 0,

Hello everyone, I'm trying to improve the Huston Todos App.

When you edit a label, the completed style appears next to it. I want that when you press the "save" button, the label comes back to normal.

I've added this code:

for (var todo in todos) {
      todo.edited = false;
 }

I know that it's correct, but I've also understood that when you create a property with angular declaration the property isn't writable. And this is should be the reason of the error.

I think that a solution would be to modify the json obejects, writing the property there and declaring it as writable. But I was wondering if there would be another way, just with angular.

Thank you, I give you the link of the workspace.

https://w.trhou.se/km97x59cqi

1 Answer

akak
akak
29,445 Points

Hi,

When you click save on either todo all todos that were edited are saved. That how current code works. To get rid of EDITED annotation you can set that value to false before you send data to the service.

var filteredTodos = $scope.todos.filter(function(todo) {
      if (todo.edited) {  
          todo.edited = false;
        return todo;
      }
    });

The service that saves your data ideally should know nothing about what is displayed on the page. Controller is what binds data with view and inside of it you should modify the property to update the view.

Hope that helps. Cheers!