Javascript 角度4:具有动态数据的表格
我试图用angular 4创建一个动态表,但我不允许将*ngFor与tr一起使用?你知道怎么解决这个问题吗Javascript 角度4:具有动态数据的表格,javascript,angular,ngfor,Javascript,Angular,Ngfor,我试图用angular 4创建一个动态表,但我不允许将*ngFor与tr一起使用?你知道怎么解决这个问题吗 <table class="table table-bordered table-sm m-0"> <thead class=""> <tr> <th>FirstName</th> <th>Name</th> <th>Registration Date</t
<table class="table table-bordered table-sm m-0">
<thead class="">
<tr>
<th>FirstName</th>
<th>Name</th>
<th>Registration Date</th>
<th>Phone</th>
<th>E-mail address</th>
<th>Role</th>
</tr>
</thead>
<tbody >
<tr *ngFor="user in users">
<td>{{user.firstName}}</td>
<td>{{user.lastName}}</td>
<td>{{user.registrationDate}}</td>
<td>{{user.phoneNumber}}</td>
<td>{{user.email}}</td>
<td>{{user.userRole}}</td>
</tr>
</tbody>
</table>
名字
名称
注册日期
电话
电子邮件地址
角色
{{user.firstName}
{{user.lastName}
{{user.registrationDate}
{{user.phoneNumber}
{{user.email}
{{user.userRole}
确切的错误是:
compiler.es5.js:1690未捕获错误:模板解析错误:无法绑定
由于“ngFor”不是“tr”的已知属性。("
]*ngFor=“用户中的用户”>
{{user.firstName}
{{user.lastName}}”):ng:///AppModule/UserListComponent。html@15:10无法绑定到“ngForIn”
因为它不是“tr”的已知属性。(”
您的
ngFor
是错误的,因为ngForIn
已弃用()
{{user.first{u name}
{{user.last_name}
在angular的新语法中,需要为结构指令声明局部变量。 所以使用
{{user.firstName}
{{user.lastName}
{{user.registrationDate}
{{user.phoneNumber}
{{user.email}
{{user.userRole}
let关键字声明您在模板中引用的模板输入变量。*n如果语法错误,请尝试此方法。它应该是“让用户的用户”而不是“让用户的用户”乐意帮助您。:)
<tr *ngFor="let user of users">
<td>{{user.first_name}}</td>
<td>{{user.last_name}}</td>
</tr>
<tr *ngFor="let user of users">
<td>{{user.firstName}}</td>
<td>{{user.lastName}}</td>
<td>{{user.registrationDate}}</td>
<td>{{user.phoneNumber}}</td>
<td>{{user.email}}</td>
<td>{{user.userRole}}</td>
</tr>