Lekz Flores Lekz Flores - 8 months ago 18
AngularJS Question

Get objects and values inside an array at the same time

I'm using

and a
file to hold my data. And my data holds an array with objects and some values.

Here's my JSON:

"_id": 2,
"navLvl": 1,
"codeName": "BOD",
"DirectoryName": "Board of Directors",
"Contacts": [
"BodName": "FVC",
"Position": "CEO",
"LocalNo": "101",
"Mobile": ["09178985698", "09178985698"]
"BodName": "MIC",
"Position": "PRESIDENT",
"LocalNo": "108",
"Mobile": ["09178710088", "09178889088"]
"BodName": "SIC",
"Position": "SVC-OPTRNS",
"LocalNo": "105",
"Mobile": ["09178923689", "09328922955"]

And in my controller:

var result = $filter('filter')(data.DirectoryList, {_id:$stateParams.id})[0];

$scope.listviews = [];
angular.forEach(result, function(value, key) {


And in my views:

<div class="table-responsive" ng-if="listviews[0] == 2">
<table class="table table-striped table-hover table-condensed table-bordered">
<th>BOD Name</th>
<th>Local No.</th>
<tbody ng-repeat="list in listviews[4]">
<td ng-repeat="(key, value) in list">{{ value }}</td>

This gives me:

BOD Name | Position |Local No. | Mobile
FVC | CEO | 101 | ["09178985698","09178985698"]
MIC | PRESIDENT| 108 | ["09178710088","09178889088"]
SIC |SVC-OPTRNS| 105 | ["09178923689","09328922955"]

I have no idea how to display it correctly but when I try to change the
I can get the first array but it ruins the data holds by objects. Is there another way getting the data from objects together with values? Can't figure out where should I execute the logic. Is it way better in the controller or in my view?


I'm pretty sure there is a lot of different ways on doing this. The following is one that should work.

        <tbody ng-repeat="list in listviews[4]">
            <td ng-repeat="(key, value) in list">
                <div ng-if="key=='Mobile'" ng-repeat="phone in value">{{phone}} </div>
                <div ng-if="key!='Mobile'">{{value}}</div>