How can I filter the displayed array and re-display the filtered list?
So I am creating a simple to do list for AngularJS. I manage to add a list, but when I go to create a controller to filter out the completed do-dos and re-display the unfinished do-boards to the screen, I have an error that I cannot find out. I think my ng-submit is not working because it cannot call the function I want to call when the button was clicked. Any help is appreciated.
This is my html file:
<div ng-contoller="CompletedController as completeCtrl">
<input class="clearbutton" type="submit" value="Clear Completed" ng-submit="completeCtrl.unfinished()"></input>
</div>
and my jsfile:
app.controller('CompletedController', function(){
todoCtrl.currentTodos = [];
this.unfinished = $filter('filter')(todoCtrl.currentTodos, array, function(currentTodo){
return !currentTodo.status;
});
todoCtrl.currentTodos = this.unfinished;
});
source to share
You cannot access the controller scope from another controller scope the way you are calling todoCtrl.currentTodos
. You will need to either merge the controllers or communicate between them using a service / factory.
Your error unfinished
, if I understood you correctly, can be solved with:
app.controller('CompletedController', function($scope){
$scope.unfinished = function(){
//function content
}
});
source to share