Misael Tovar
Misael Tovar

Reputation: 77

ng-repeat & javascript object

here is my object:

     $scope.tickets = [{
         title: "Bug 1",
         number: 1,
         desc: 'Description #1',
         assigned: [{
             name: "Someone",
             group: "Development"
         }]
     },
     {
         title: "Bug 2",
         number: 2,
         desc: 'Description #1',
         assigned: [{
             name: "someone2",
             group: "Development"
         }]
     },
     {
         title: 'Random unknown issue',
         number: 3,
         desc: 'Description #3',
         assigned: [{
             name: "Someone3",
             group: "Support"
         }]
     }];
  1. I am doing a table to display all the content and inside im doing an hg-repeat but i do not know how to access the name and group info under the assigned

    <p class="lead">Development:</p>
    <div class="table-responsive">
      <table class="table table-striped table-condensed">
        <thead>
          <tr>
            <!-- <th>index</th> -->
            <th>#</th>
            <th>Title</th>
            <th>Description</th> 
            <th>Group/Assigned</th>
            <th>Advanced</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="ticket in tickets">
            <td>{{ticket.number}}</td>
            <td>{{ticket.title}}</td>
            <td>{{ticket.desc}}</td>
            <td>{{ticket.assigned.group}} / {{ticket.assigned.name}}</td>
            <td>
              <button class="btn btn-primary" ng-click="sendToSupport(ticket)">Send to Support</button>
            </td>
          </tr>
        </tbody>
      </table> 
    </div>  
    
  2. I have tried filtering the ng-repeat by

     | filter: {group: 'Support'}
    

and does not work

  1. aslo as you can see im sending the object into an ng-click

    <tr ng-repeat="ticket in tickets">
     <td>{{ticket.number}}</td>
     <td>{{ticket.title}}</td>
     <td>{{ticket.desc}}</td>
     <td>{{ticket.assigned.group}} / {{ticket.assigned.name}}</td>
     <td>
      <button class="btn btn-primary" ng-click="sendToSupport(ticket)">Send to Support</button>
     </td>
    

what i am doing is this

      $scope.sendToDev = function(ticket){
        this.ticket.assigned.group = "Support"
     }

seems ok?

Upvotes: 0

Views: 235

Answers (1)

Galdo
Galdo

Reputation: 945

You defined assigned as an array of object

assigned: [{
             name: "Someone3",
             group: "Support"
         }]

Define it as a object (without the []) or access it as an array.

assigned: {
             name: "Someone3",
             group: "Support"
         }

If you really need it to be an array, use a nested ng-repeat like this :

<td><div ng-repeat="assigned in ticket.assigned">{{assigned.group}} / {{assigned.name}}</div></td>

Upvotes: 2

Related Questions