Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-repeat with filter - notarray error

I have a list of items that I'm displaying with ng-repeat. I want to add a filter to show/hide archived items.

I have added a checkbox:

<input type="checkbox" ng-model="queryFilter.archived">Show archived messages

In my controller I have this:

$scope.queryFilter = {
    archived: false
};

My list of items is displayed in a table. I've tried the following:

<tr ng-repeat="message in messages | filter : queryFilter">

<tr ng-repeat="message in messages | filter : { archived: queryFilter.archived }">

<tr ng-repeat="message in messages | filter : queryFilter track by $index">

I get this error:

Error: [filter:notarray]

Expected array but received: {}

The filtering does work but I want to know why I am getting the error.

like image 670
PeteGO Avatar asked May 22 '16 13:05

PeteGO


1 Answers

I had initialised messages as an object.

Changing $scope.messages = {}; to $scope.messages = []; made the error go away.

like image 147
PeteGO Avatar answered Sep 28 '22 18:09

PeteGO