Angular ng-repeat Error “Duplicates in a repeater are not allowed.”

后端 未结 10 2559
青春惊慌失措
青春惊慌失措 2020-11-22 06:11

I am defining a custom filter like so:

10条回答
  •  青春惊慌失措
    2020-11-22 06:46

    What do you intend your "range" filter to do?

    Here's a working sample of what I think you're trying to do: http://jsfiddle.net/evictor/hz4Ep/

    HTML:

    Item {{$index}}
    Comment {{$index}} {{comment}}

    JS:

    angular.module('manyminds', [], function() {}).filter('range', function() {
        return function(input, min, max) {
            var range = [];
            min = parseInt(min); //Make string input int
            max = parseInt(max);
            for (var i=min; i<=max; i++)
                input[i] && range.push(input[i]);
            return range;
        };
    });
    
    function MainCtrl($scope)
    {
        $scope.items = [
            {
                comments: [
                    'comment 0 in item 0',
                    'comment 1 in item 0'
                ]
            },
            {
                comments: [
                    'comment 0 in item 1',
                    'comment 1 in item 1',
                    'comment 2 in item 1',
                    'comment 3 in item 1'
                ]
            }
        ];
    }
    

提交回复
热议问题