我正在尝试导入客户列表,我想继续使用有关客户的特定信息的个性化客户页面(使用功能showit)。我目前有这个:
<table ng-controller="patientsCtrl" class="table-responsive" class="fixed">
<thead>
<th>ID</th>
<th>Name</th>
<th>Policy Nr</th>
<th>Pol. Type</th>
<th>Check</th>
</thead>
<tbody>
<tr ng-repeat="p in patients | orderBy:'patID'">
<td>{{ p.patID }}</td>
<td>{{ p.name }}</td>
<td>{{ p.policy_number }}</td>
<td>{{ p.policy_type }}</td>
<td> <button ng-click="showit(p.name)">check</button> </td>
</tbody>
</table>
答案 0 :(得分:1)
假装它写的是
<button ng-click="vari=true">check</button>
。在桌子内部时按钮不起作用(我稍后将实现的功能阶段)
您有一个范围问题。该按钮在表内工作,但由于范围层次结构,数据不会超出表格。
<div ng-controller="patientsCtrl">
<p>{{vari}}</p>
<table class="table-responsive" class="fixed">
<thead>
<th>ID</th>
<th>Name</th>
<th>Policy Nr</th>
<th>Pol. Type</th>
<th>Check</th>
</thead>
<tbody>
<tr ng-repeat="p in patients | orderBy:'patID'">
<td>{{ p.patID }}</td>
<td>{{ p.name }}</td>
<td>{{ p.policy_number }}</td>
<td>{{ p.policy_type }}</td>
<td> <button ng-click="$parent.vari=true">check</button> </td>
</tbody>
</table>
<p>{{vari}}</p>
</div>
ng-repeat
为集合中的每个项目创建一个范围。要将数据放在控制器的范围内,请使用$parent
。
来自文档:
ngRepeat
指令从集合中为每个项目实例化一次模板。每个模板实例都有自己的范围,其中给定的循环变量设置为当前集合项,$index
设置为项索引或键。