rlsaj
rlsaj

Reputation: 735

AngularJS ng-repeat only show specify key value

My data structure is:

{"code":"AAA","name":"AAA industries","date":null}

I am trying to display just the name in a button. I am trying to use the following:

<div ng-repeat="item in company.details">
    <button ng-repeat="(key, val) in item">
        {{val}}
    </button>
</div>

but of course that displays everything. What's my next step here?

Upvotes: 1

Views: 2085

Answers (3)

harkl
harkl

Reputation: 901

Kolban is correct. So in your case the answer would be:

<div ng-repeat="item in company.details"> {{item.val}} </div>

Upvotes: 0

Kolban
Kolban

Reputation: 15246

Here is a jsBin illustrating an answer.

The code logic is as follows:

<body ng-app="MyApp" ng-controller="myController">
  <div ng-repeat="item in data">
    {{item.name}}
  </div>
</body>

Upvotes: 0

A.B
A.B

Reputation: 20445

use this

check for key, if it is equal to name then display else dont

 <div ng-repeat="item in company.details">
        <button ng-repeat="(key, val) in item">
            <span ng-if="key=='name'">{{val}}</span>
        </button>
    </div>

Upvotes: 2

Related Questions