ng-repeat添加空白

时间:2014-07-09 04:05:36

标签: javascript html angularjs

我是Angular的新手,我正在尝试使用ng-repeat创建一个表来生成<tr>

我的控制器

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

我的工厂

.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>

现在由于一些奇怪的原因,这是html我正在找回正确的东西但是有空的<td>元素。

<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>

这里发生了什么,为什么有多个空<td>

1 个答案:

答案 0 :(得分:2)

close your `<td>`

 <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>