Dynamically displaying JSON data

by Aieman Siddique

HTML

<body ng-app="app" ng-controller="project"> 

<table class="table">
	<tbody>
		<tr ng-repeat="(key, value) in device">
			<td><strong>{{key}}</strong></td>
			<td>{{val(value)}}</td>
		</tr>
	</tbody>
</table>
    
</body>

JavaScript

var app = angular.module('app', []);

var project = function ( $scope ) {

    $scope.device = 

        {
            "name": "device1", 
            "vendor": "intel",
            "category": "Antenne",
            "stockID": "",
            "files": [
                {"name": "manual_device1.pdf"}
            ],
            "params": [
                {"freq": "123"},
                {"maxFreq": "200"}
            ],
            "owner": ""
        }
    $scope.val = function(value) {
        if(typeof value == 'string') {return value}
        else if(typeof value == "object") {
            var values="";
            var len=value.length;
        
            value.forEach(function(val,index){
                for(key in val){
                    values+=val[key]+", ";
                }
                
           });
            return values;
    }
}
}