0

I am learning Angular now and got stuck here. What I have tried is:

<tr ng-show="data in myData17.layouts | limitTo:2 | slice:1">
  <td>{{data.name}}</td>
  <td>{{data.cards[1].cardNo}}</td>
  <td>{{data.cards[1].cardType}}</td>
  <td>{{data.cards[1].ports[0].portNo}}</td>
  <td>{{data.cards[1].ports[0].portName}}</td>
  <td>{{data.cards[1].ports[0].portType}}</td>
  <td>{{data.cards[1].ports[0].portspeed}}</td>
  <td>{{data.cards[1].ports[0]["ds-scheduler-node-profile"]}}</td>                  
</tr>

where layouts is an array that has up to 10 elements in it but I want to access the data that is in index=1.

4
  • 1
    It is not so clear what you want to display. You need only one row? Can you show a sample of the data array? ng-show doesn't have that syntax, ng-repeat does Commented Dec 26, 2019 at 12:53
  • bill, in a simple way I wanted to display only one index value in an array of say 10 indexes. Thanks anyway I got help! Commented Dec 27, 2019 at 7:34
  • If this is the case, then you don't even need to use ng-repeat. There is no reason to loop through the entire array Commented Dec 27, 2019 at 8:29
  • 1
    I need ng-repeat to loop through that selected index which is again an array Commented Dec 27, 2019 at 9:37

1 Answer 1

2

You use ng-repeat instead of ng-show for looping and use $index for accessing item.

<tr ng-repeat="data in myData17.layouts">
  <td ng-show="$index==0">{{data.name}}</td>
  <td ng-show="$index==0">{{data.cards[0].cardNo}}</td>
  <td ng-show="$index==0">{{data.cards[0].cardType}}</td>
  <td ng-show="$index==0">{{data.cards[0].ports[0].portNo}}</td>
  <td ng-show="$index==0">{{data.cards[0].ports[0].portName}}</td>
  <td ng-show="$index==0">{{data.cards[0].ports[0].portType}}</td>
  <td ng-show="$index==0">{{data.cards[0].ports[0].portspeed}}</td>
  <td ng-show="$index==0">{{data.cards[0].ports[0]["ds-scheduler-node-profile"]}}</td>                  
</tr>
Sign up to request clarification or add additional context in comments.

2 Comments

Ashish this works fine. thanks but can I print those cardNo, cardType etc values dynamically using another ng-repeat inside but not sure how, any suggestions?
yes you can print those value also using nested ng-repeat <td ng-show="$index==0"><span ng-repeat="card in data.cards">{{card.cardNo}}</span></td>. For structure data you have to create table layout accordingly.

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.