Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ng-repeat for comma separated strings

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.

like image 949
aldimeola1122 Avatar asked Apr 07 '15 08:04

aldimeola1122


2 Answers

Here is plunker for you

You need to use track by $index because it is having duplicate value in array.

ng-repeat="icerik in arrString track by $index"
like image 122
squiroid Avatar answered Sep 18 '22 14:09

squiroid


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

like image 33
mohamedrias Avatar answered Sep 16 '22 14:09

mohamedrias