rebello rebello - 1 year ago 72
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>

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 Source

Use the string.split method:

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download