Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular print string array without quotes

I have a simple string array coming from a server:

[{"things":["me", "my"]}]

In my page, to display the array I have:

{{things}}

And it prints:

["me", "my"]

How do I control the printing, for instance, if I want to eliminate the brackets and quotes?

like image 559
bmw0128 Avatar asked Dec 02 '14 00:12

bmw0128


2 Answers

I think you'll want ngRepeat for something like:

<div class="list" ng-repeat="thing in things">
  {{ thing }}
</div>
like image 79
thataustin Avatar answered Oct 06 '22 01:10

thataustin


You can implement a scope function to display arrays as comma separated strings like shown in this fiddle.

$scope.array = ["tes","1","2","bla"];

$scope.arrayToString = function(string){
    return string.join(", ");
};

Now you can call this function within the template:

{{arrayToString(array)}}

Update

You can also use the join() method of arrays directly within the template without using an extra function inbetween as displayed within the updated fiddle.

{{array.join(", ")}}
like image 38
Daniel Avatar answered Oct 06 '22 00:10

Daniel