首页 > 代码库 > angular 数据内容有重复时不显示问题

angular 数据内容有重复时不显示问题

<body ng-app="app">
    <div ng-controller="myctl">
        <ul>
            <li ng-repeat="item in arr">
                {{item}}
            </li>
        </ul>
    </div>

    <script>
        angular.module("app", []).controller("myctl", function ($scope, $http) {
            $scope.arr = ["dd", "aa", "cc", "aa"];
        });
    </script>
</body>

 arr中有字符串"aa"重复,angular无法显示重复,想要显示可以加上:track by $index

<li ng-repeat="item in arr track by $index">

 

angular 数据内容有重复时不显示问题