I am working on a note-taking app.
I want my app to delete all checked radios on clicking the 'Remove' link. An insight into the code:
HTML:
<p>[ <a href='#/home'>Cancel</a> | <a href='#/home/edit' ng-click='remove()'>Remove</a> ]</p>
<table border='0'>
<tbody>
<tr ng-repeat='note in notes'>
<td>
<input type='radio' ng-model='note.rmv'></input>
</td>
<td>{{note.text}}</td>
</tr>
</tbody>
</table>
Controller:
app.controller('editCtrl', ['$scope', 'notes', function($scope, notes) {
$scope.notes = notes.notes;
$scope.remove = function() {
for (var i = 0; i < $scope.notes.length; ++i) {
if ($scope.notes[i].rmv) {
delete $scope.notes[i];
notes.getLost($scope.notes[i]._id);
}
}
};
}]);
Factory:
app.factory('notes', ['$http', function($http) {
var t = {
notes: []
};
t.getLost = function(id) {
return $http.delete('/home/edit').success(function(data) {
return t.getAll();
});
};
return t;
};
What might be doing wrong here?
$scope.notessuddenly change to$notes.notes? Meaning that you first loop$scope.notesthen in that loop you check$notes.notes[i]..getLostis really lost.. :) read the angular docs.. you should rewrite whole thing..