rebello rebello - 2 months ago 6
AngularJS Question

Split a string from JSON and display it in ng-repeat

<div ng-controller="countryCtrl">
<div class="m-b-20" ng-repeat="val in records">
{{val.Country}} <br>
</div>
</div>

var app = angular.module('app', [])
.controller('countryCtrl', ['$scope', function($scope) {
$scope.records = [{
"Country": "Germany,France,UK,Japan"
}, {
"Country": "Sweden,Australia,USA"
}, {
"Country": "Mexico,Colombia,Brazil"
}, {
"Country": "Austria,UAE,Kenya"
}]
}])


Instead of displaying country in a string need to split the countries and display it as bullet points.

Answer

Use the string.split method:

<div class="m-b-20" ng-repeat="val in records">
    <ul>
        <li ng-repeat="country in val.Country.split(',')">{{ country }}</li>
    </ul>
</div>

JSFIDDLE