Skip to content Skip to sidebar Skip to footer

How To Repeat "key" In Ngrepeat One Time Only (angularjs)

The problem is leaving in the JSON Array response from the Backend/DB. I'm getting the response of the database in the correct json format: [ 0: { 'Grade': 100, 'AB

Solution 1:

If you have the exact same keys in each object in the array, you could achieve this with:

<thead><tr><thng-repeat="(key, value) in data[0]">
        {{key}}
    </th></tr></thead>

In your snippet you are doing a double loop, listing each key, for each element in the array.

Solution 2:

You could use the unique filter from AngularUI (source code available here: AngularUI unique filter) and use it directly in the ng-options (or ng-repeat).

Try This:

<thead><trng-repeat="d in data"><thng-repeat="(key, value) in d | unique:'key'">
          {{key}}
      </th></tr></thead>

Solution 3:

this answer may be help you

<thead>
<tr ng-repeat="d in data">
   <th ng-if="$parent.$index == 0" ng-repeat="(key, value) in d">
       {{key}}
   </th>
</tr>

Post a Comment for "How To Repeat "key" In Ngrepeat One Time Only (angularjs)"