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

glenn romaniuk
glenn romaniuk
32,520 Points

Angular - How can i set default value base on a model property

I have the following todo template. I want to set the default property 'edited' equal to false if the 'todo' does not have an '_id'. Note todo is a json object and the object does not have an _id.

<div class="item" ng-class="{'editing-item': editing, 'edited': todo.edited, 'completed': todo.completed}" ng-repeat="todo in todos | orderBy: 'completed' " ng-init="todo.completed = false">
  <input type="checkbox" ng-model="todo.completed" />
  <span ng-click="todo.completed = !todo.completed; todo.edited = true"></span>
  <label ng-hide="editing" ng-click="editing=true">{{todo.name}}</label>
  <input ng-show="editing" ng-blur="editing = false" class="editing-label" type="text" ng-model="todo.name" ng-change="todo.edited = true"/>
  <div class="actions">
    <a href="" ng-click="saveTodos()">Save</a>
    <a href="" class="delete" ng-click="deleteTodo(todo, $index)">Delete</a>
  </div>
</div>