Angular js过滤器:notarray,通过ng-repeat填充的列表

时间:2017-04-04 20:49:20

标签: angularjs angularjs-ng-repeat ng-options

我已经使用ng-repeat指令创建了一个列表,并希望使用ng-options指令对其进行过滤。但是,无论过滤器是作为空数组还是作为空对象在作用域中初始化,我都会收到错误:[filter:notarray]。我已经为选择下拉列表尝试了不同的方法,但是我仍然遇到了同样的错误:

这是我的过滤器:

<select name="project-filter" id="" ng-model="projectFilter" ng-options="task.project for task in tasksList">
    <option value="">All</option>
</select>

以下是我想要过滤的列表:

<li ng-repeat='task in tasksList | filter : projectFilter' class="list-element">
    <a href="" ng-click="taskDetails()">
        <div class="content">
            <div class="name-and-date">
              <span class="task-name">{{task.name}}</span> <span class="due-date">{{task.dueDate}}</span> 
            </div>
            <div class="additional-info">
              <span>{{task.project}}</span>
            </div>
        </div>
    </a> 
</li>

这是控制器代码:

angular.module('toDoApp')

.controller('mainController', function($scope, $rootScope, saveTaskService, retrieveTasksFactory) {
    var newTaskPopUp = document.getElementById('new-task-pop-up'),
        filterProjecTypeDropdown = document.getElementById('filter-project-type-dropdown');
    $scope.task = {
        name: '',
        project: '',
        dueDate: '',
        priority: '',
        tags: '',
        parent: '',
        comments: '',
        reminders: ''
    };

    $scope.projectFilter = {};

    $scope.showList = false;

    $rootScope.tasksList = {};
    retrieveTasksFactory.getTasksList()
    .then(function (tasks) {
        $rootScope.tasksList = tasks;
        if (tasks.length > 0) $scope.showList = true;
        console.log($rootScope.tasksList);
    }, function (error) {
        console.error(error);
    });
}

有人可以解释一下我做错了什么或错过了什么?提前感谢您的帮助。

0 个答案:

没有答案