0
我在這裏有兩個場景,一個是用戶單擊一個單獨的元素並提交,另一個是用戶單擊選擇所有按鈕並提交,以便根據用戶的要求,我想在控制器中獲取物品的詳細信息。Angular複選框選擇全部或從表中選擇個別元素
這裏是我的代碼
HTML
<div >
<label class="btn btn-info">
<input ng-model="vm.selectAll" type="checkbox" name="selectAll" value="allitems" > Select all Items
</label>
<button ng-click="vm.purchaseItems(item)" class="btn btn-danger" type="submit" >Purchase selected Items</button>
<table ng-repeat="item in vm.items">
<tbody>
<thead>
<th ><input type="checkbox" ng-checked="vm.selectAll"/></th>
<th >Student Id</th>
<th >Name</th>
<th >School</th>
</thead>
<tr>
<td></td>
<td >{{item.studentId}}</td>
<td >{{item.name}}</td>
<td >{{item.schoolName}}</td>
</tr>
</tbody>
</table>
</div>
控制器
vm.purchaseItems = purchaseItems;
function purchaseItems(item) {
console.log(item);
// I want to log only selected items either single or all based on user call
}
我應該去同一個指令還是可以在控制器本身只是做了什麼?
需要篩選複選框模型項目爲true –
使用Github上的這個演示:HTTPS: //vitalets.github.io/checklist-model/ – Abhishek
@Abhishek很好,但也有很多錯誤 –