6

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.

2
  • i've edit it again, it doesn't work still Commented Apr 7, 2015 at 9:00
  • You can't have td outside of table. You can use some other html tag elements Commented Apr 7, 2015 at 9:04

4 Answers 4

3

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"
Sign up to request clarification or add additional context in comments.

2 Comments

kudos track by is one thing, also the OP has used td which was not displaying. Even in your example, you've replaced it with p tag :)
@mohamedrias i used <p> in my example of plunker .I know it must be the small demo he is trying to show that's why i didn't considered that. :)
3

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

Comments

1

if you want to repeat s tring saperated with ,, you shall split the string to an array and the repeat

try this:

  $scope.string = $scope.string.split(",");

this creates an array from string that is split from ,.

so your code becomes:

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.str= str.split(",");
        $scope.arrString = new Array();
        $scope.arrString = $scope.string.split(',');
    });

Comments

1
<td ng-repeat="L in Labour.CWCT_Description.split(',') track by $index" >
                                        {{L}}
                                    </td>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.