无法使Angular过滤器运行ng-options

时间:2017-01-25 19:38:12

标签: javascript angularjs ng-options angularjs-ng-options

所以我正在使用Angular版本1.5.7并从服务器接收一个看起来像这样的对象:

var app = angular.module('myApp', []);function ctrl($scope){
$scope.properties.Consultants = [
    {
        text:"consultant1",
        Group: {Name:"CorporateResource", Disabled:"False"}
    },
    {
        text:"consultant2",
        Group: {Name:"CorporateResource", Disabled:"False"}
    },
    {
        type:"consultant3",
        Group: {Name:"Resource", Disabled:"False"}
    },
    {
        type:"consultant4",
        Group: {Name:"Resource", Disabled:"False"}
    }
];

}

我需要过滤基于Group.Name创建的选择列表选项,只获取具有Group.Name ==" CorporateProject"的值。我尝试了以下的许多变体,但似乎无法正确过滤:

<select ng-model="test" ng-options="c as c.text for c in properties.Consultants| filter:{Group.Name: 'CorporateResource'}"></select>

我不断抛出以下js错误: enter image description here

1 个答案:

答案 0 :(得分:1)

你有错误的过滤器,它应该如下所示

ng-options="c as c.text for c in properties.Consultants 
             | filter: {Group: {Name: 'CorporateResource'}}"

Demo Plunker