When you have an array of objects, how do you go about binding the changes of an object to firebase?
data looks like this:
[{ title: "Do Something", Due: "1425121200000", assignedTo: "Bill", description: "Do something", $id: wqejkkjebiewdf},
{ title: "Do Something else", Due: "1425121200000", assignedTo: "Jim", description: "Do something else", $id: owenuwefwfliu}]
js:
var todos = this;
todos.tasks = [];
var todoRef = new Firebase(FB + "/tasks/" + CurrentFarm);
var todoArray = $firebase(todoRef).$asArray();
todoArray.$loaded(todos.tasks = todoArray);
html to show todos:
<div ng-repeat="task in todo.tasks | orderBy:'when'| filter: {done: true}">
<input type="checkbox" ng-model="task.done" ng-change="todo.taskDone(task)">
<span ng-repeat="users in task.users">{{getName(users)}} </span>
<span> {{task.title}} </span>
<span> {{task.when | date:"EEEE, d MMMM, y"}} </span>
<input ng-click="editTask()" type="button" value="Edit">
</div>
html for editing a todo. Note that I removed certain inputs from this code like date pickers etc to make it more readable.
<div ng-show="editTaskMenu">
<form novalidate>
<input ng-model="task.title" type="text" value="{{task.title}}">
<textarea ng-model="task.description" value="{{task.description}}"></textarea>
<input type="submit" value="Done" ng-click="finishedEditing()">
</form>
</div>
The changes bind to the array in angular but do not get updated in firebase. From what I can tell there is no way to do three way binding with an array, so what is the work around here?
$asArrayto show a list of items (song-repeatover them) and then allow editing of the selected object's properties through three-way binding (with$asObjectand$bindTo). As usual: the bet way is the one that works for you use-case(s).