我是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>
答案 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>