0

I'm quite new to Angular, and I've managed to get here:

 <tr ng-repeat="spec in res">
     <td> {{$index + 1}} </td>
     <td>{{ spec }}</td>             
 </tr>

Currently, my output is:

[["suite1",{"id":"suite1","description":"test cases","fullName":"my cases","failedExpectations":[],"status":"finished","specs":[{"id":"spec0","description":"should be able to add an unit","fullName":"etc cases","failedExpectations":[],"passedExpectations":[],"pendingReason":"","status":"passed"}]},"timestamp: Thu Apr 20 2017 09:47:38 GMT+0300 (EEST)"]]

How do I display a specific field? (for example the ID. Or the description. or the full name?

Edit: I am using Angular 1.6.3.

EDIT2 :

json result

 <pre>{{ res | json }}</pre>

result here

[
  "[[\"suite1\",{\"id\":\"suite1\",\"description\":\"test cases\",\"fullName\":\"my cases\",\"failedExpectations\":[],\"status\":\"finished\",\"specs\":[{\"id\":\"spec0\",\"description\":\"should be able to create a room\",\"fullName\":\"should be able to add an unit\",\"failedExpectations\":[],\"passedExpectations\":[],\"pendingReason\":\"\",\"status\":\"passed\"}]},\"timestamp: Thu Apr 20 2017 09:47:38 GMT+0300 (EEST)\"]]"
]

i also created a small function that translate the array into an object:

function toObject(arr) {
       let rv = {};
        for (let i = 0; i < arr.length; ++i)
             if (arr[i] !== undefined) rv[i] = arr[i];
        return rv;
        }

    console.log(toObject(events));
    $scope.res = toObject(events); 

or

    $scope.res = toObject(events); 

made no difference

This, translate the data, into this:

Object {0: "[["suite1",{"id":"suite1","description":"RW - rate…tamp: Fri Apr 21 2017 11:45:06 GMT+0300 (EEST)"]]", 1: "[["suite1",{"id":"suite1","description":"rates","f…tamp: Fri Apr 21 2017 11:45:55 GMT+0300 (EEST)"]]", 2: "[["suite1",{"id":"suite1","description":"rates","f…tamp: Fri Apr 21 2017 11:46:12 GMT+0300 (EEST)"]]"}

3 Answers 3

1

enter image description hereHere is the solution for it Jsfiddle link

updated jsfiddle link

JS code

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

  app.controller('ctrl', function($scope) {
    $scope.res = [
      ["suite1", {
        "id": "suite1",
        "description": "test cases",
        "fullName": "my cases",
        "failedExpectations": [],
        "status": "finished",
        "specs": [{
          "id": "spec0",
          "description": "should be able to add an unit",
          "fullName": "etc cases",
          "failedExpectations": [],
          "passedExpectations": [],
          "pendingReason": "",
          "status": "passed"
        }]
      }, "timestamp: Thu Apr 20 2017 09:47:38 GMT+0300 (EEST)"]
    ];
  });

HTML

  <div ng-app='myApp' ng-controller='ctrl'>
    <table border='1'>
      <tr>
        <th>
          ID
        </th>
        <th>Full Name
        </th>
      </tr>
      <tr ng-repeat="spec in res">
        <td> {{$index + 1}} </td>
        <td>{{ spec[1].fullName }}</td>
      </tr>

    </table>
  </div>

hope this will help you

Sign up to request clarification or add additional context in comments.

7 Comments

checkout the picture uploaded
I have an extra " in the $scope.res, see edited json output
if I try to parse the JSON, i get this: SyntaxError: Unexpected token , in JSON at position 385
please post it here, your json
Yes. Please see here. pasted.co/5093fa38 the json is not edited, parsed at all. I also created a small function that translates the array into an object (see in reedited main post) but I am still not able to render the fields.
|
0
 <tr ng-repeat="spec in res">
 <td>{{:: $index + 1}} </td>
 <td>{{:: spec }}</td>  
 <td>{{:: spec.ID }}</td>             
 <td>{{::spec.fullName }}</td>                        

1 Comment

the index counter and the spec gets rendered (just like exemplified above. the ID and the fullName does not.
0

since this is a multi-dimensional array you need to use nested ng-repeats

 <table>

  <tr ng-repeat="spec in res track by $index">
     <td>
     <table> 
      <tr ng-repeat="spe in spec track by $index">
         <td>{{ spe.id }}</td>    
         <td>{{ spe.fullName }}</td>             
     </tr>
     </table>
     </td>           
 </tr>
 </table>

angular.module("app",[])
.controller("ctrl",function($scope){
$scope.res = [["suite1",{"id":"suite1","description":"test cases","fullName":"my cases","failedExpectations":[],"status":"finished","specs":[{"id":"spec0","description":"should be able to add an unit","fullName":"etc cases","failedExpectations":[],"passedExpectations":[],"pendingReason":"","status":"passed"}]},"timestamp: Thu Apr 20 2017 09:47:38 GMT+0300 (EEST)"]]


})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <table>
 
  <tr ng-repeat="spec in res">
     <td>
     <table> 
      <tr ng-repeat="spe in spec">
         <td>{{ spe.id }}</td>    
         <td>{{ spe.fullName }}</td>             
     </tr>
     </table>
     </td>           
 </tr>
 </table>
</div>

2 Comments

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: spe in spec, Duplicate key: string:[, Duplicate value: [
added res | json output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.