How to display an item from an enum in my table using AngularJs?

2

I have a table where I make a ng-repeat , so far normal.

<tr data-ng-repeat="item in itemsconfiguration">
                            <td>{{::item.Description}}</td>
                            <td>{{::item.Order}}</td>
                            <td>{{::item.Type}}</td>
                            <td><span ng-if="item.Active"></span></td>                            
                        </tr>

InmycontrollerI'malreadybringingtheenums...

AuditingItemType.query().$promise.then(function(itemtypes){$scope.itemtypes=itemtypes;})

JsonthatIgetfromtheenumtable

[{"$id":"1","Id":0,"Name":"TEXT"},{"$id":"2","Id":1,"Name":"QUANTITY"},{"$id":"3","Id":2,"Name":"MULTIPLE"}]

How can I display it in my table dynamically?

    
asked by anonymous 29.09.2015 / 20:57

1 answer

1

One possibility is to create an internal%%, and to filter content - only display the description when the value of ng-repeat is equal to Id of the element referenced by the main loop.

The following example:

function SampleController($scope) {

  $scope.itemsconfiguration = [
    {"Description": "Secretaria", "Order": 2, "Type":2, "Active": 0},
    {"Description": "Patrimonio", "Order": 3, "Type":3, "Active": 1},
    {"Description": "Tesouraria", "Order": 2, "Type":2, "Active": 1}
  ];

  $scope.itemtypes = [
    {"$id":"1","Id":0,"Name":"TEXT"},
    {"$id":"2","Id":1,"Name":"QUANTITY"},
    {"$id":"3","Id":2,"Name":"MULTIPLE"},
    {"$id":"3","Id":3,"Name":"OTHER"}
  ];

}
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script></head><body><divng-controller="SampleController">

      <table>
        <tr>
        <th>Descrição</th>
        <th>Ordem</th>
        <th>Tipo</th>
        <th>Ativo</th>
        </tr>
        <tr ng-repeat="item in itemsconfiguration">
          <td>{{item.Description}}</td>
          <td>{{item.Order}}</td>
          <td>

            <span ng-repeat='type in itemtypes'
                  ng-if='type.Id == item.Type'>
              {{type.Name}}
            </span>

          </td>
          <td><span ng-if="item.Active">X</span></td>       
        </tr>
      </table>
    </div>
  </body>
</html>
    
29.09.2015 / 21:51