Angular ng-repeat for comma separated strings

aldimeola1122 picture aldimeola1122 · Apr 7, 2015 · Viewed 13.3k times · Source

I've a question in angularjs.

In my controller, I've a comma separated string, and I will show it in my index.html(with ng-repeat)

Here is my controller:

myApp.controller('TabsDemoCtrl',function($scope,$http){
    $http.get('/performbatch').success(function(data) {
        $scope.string = 'Gzrgh,1,2,1,4,1,1,1,20150304,20180304';
        $scope.arrString = new Array();
        $scope.arrString = $scope.string.split(',');
    });

Here is my html :

<div ng-controller="TabsDemoCtrl">
    <td ng-repeat="icerik in arrString">
       {{icerik}}
    </td>
</div>

But I couldn't achieve that. Can you help me? Thanks in advance.

Answer

mohamedrias picture mohamedrias · Apr 7, 2015

You can't have td outside table.

It must be like

<div ng-repeat="icerik in arrString track by $index">
       {{icerik}}
</div>

Also since some are duplicates items, you must add track by $index as well

DEMO