0

This seems like it should be so simple but my brain is exploding. This is what I am trying to achieve using angular, I have my shopping list

app.controller("Destroyer", function($scope) {
    $scope.shoppingList = [
      {name: 'Milk'},
      {name: 'Eggs'},
      {name: 'Bread'},
      {name: 'Cheese'},
      {name: 'Ham'}
    ];

});

In my template I want to access the the the 3rd item for example

{{ shoppingList.name[$index == 2] }}

How do I do this? Thanks

EDIT: Answer {{ shoppingList[2].name }}

5
  • {{ shoppingList.name[2] }} ? Commented Jul 18, 2014 at 6:57
  • 1
    you can use $index only on ng-repeat Commented Jul 18, 2014 at 6:58
  • {{ shoppingList[2].name }} Commented Jul 18, 2014 at 7:00
  • {{ shoppingList.name[2] }} - this doesn't work Commented Jul 18, 2014 at 7:01
  • omg Anthony, thank you! haha I feel like such a fool cause I realise now why you put it in that position. Commented Jul 18, 2014 at 7:02

1 Answer 1

1
if you know the index you can give like this

{{shoppingList[2].name}}

or in ng-repeat 

<div ng-repeat="list in shoppingList " ng-show="$index==2">{{list.name}}</div>
Sign up to request clarification or add additional context in comments.

Comments

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.