简体   繁体   中英

ng-repeat adding blank <tr>

I'm a newb to Angular and I'm trying to create a table by using ng-repeat to generate <tr> 's

My controller

 .controller('ContactCtrl', ['$scope', 'Contact',
    function($scope, Contact) {
      $scope.contacts = Contact.query();
    }
  ])

My Factory

.factory('Contact', ['$resource', 'ENV',
    function($resource, ENV) {
      return $resource(ENV.apiEndpoint, {}, {
        query: { method:'GET', isArray:true }
        // create: { method:'POST', }
      })
    }
  ]);

my Partial

<table class="table table-striped">
    <thead>
      <tr>
        <th>first name</th>
        <th>last name</th>
        <th>phone</th>
        <th>email</th>
        <th>address</th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="contact in contacts | filter:searchParams | orderBy:orderProp">
        <td>{{contact.first_name}}</td>
        <td>{{contact.last_name}}<td>
        <td>{{contact.phone_number}}<td>
        <td>{{contact.email}}<td>
        <td>{{contact.address}}<td>
      <tr>
    </tbody>
  </table>

now for some odd reason this is the html I'm getting back the correct things but there are empty <td> elements.

<table class="table table-striped">
    <thead>
      <tr>
        <th>first name</th>
        <th>last name</th>
        <th>phone</th>
        <th>email</th>
        <th>address</th>
      </tr>
    </thead>
    <tbody>
      <!-- ngRepeat: contact in contacts | filter:searchParams | orderBy:orderProp --><tr ng-repeat="contact in contacts | filter:searchParams | orderBy:orderProp" class="ng-scope">
        <td class="ng-binding">testing</td>
        <td class="ng-binding">Test</td><td>
        </td><td class="ng-binding"></td><td>
        </td><td class="ng-binding">me@asdfa.ca</td><td>
        </td><td class="ng-binding"></td><td>
      </td></tr><!-- end ngRepeat: contact in contacts | filter:searchParams | orderBy:orderProp --><tr ng-repeat="contact in contacts | filter:searchParams | orderBy:orderProp" class="ng-scope">
        <td class="ng-binding">stuff</td>
        <td class="ng-binding">Test</td><td>
        </td><td class="ng-binding"></td><td>
        </td><td class="ng-binding">me@asdfa.ca</td><td>
        </td><td class="ng-binding"></td><td>
      </td></tr><!-- end ngRepeat: contact in contacts | filter:searchParams | orderBy:orderProp --><tr ng-repeat="contact in contacts | filter:searchParams | orderBy:orderProp" class="ng-scope">
        <td class="ng-binding">bob</td>
        <td class="ng-binding">Test</td><td>
        </td><td class="ng-binding">778-714-3492</td><td>
        </td><td class="ng-binding">me@asdfa.ca</td><td>
        </td><td class="ng-binding">1231 comce</td><td>
      </td></tr><!-- end ngRepeat: contact in contacts | filter:searchParams | orderBy:orderProp --><tr>
    </tr></tbody>
  </table>

what is going on here why is there multiple empty <td>

close your `<td>`

like

 <tr ng-repeat="contact in contacts | filter:searchParams | orderBy:orderProp">
    <td>{{contact.first_name}}</td>
    <td>{{contact.last_name}}</td>
    <td>{{contact.phone_number}}</td>
    <td>{{contact.email}}</td>
    <td>{{contact.address}}</td>
  </tr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM