mardi 31 janvier 2017

Angular checkbox select all or select individual element from the table

I have two scenarios here, one is user click an individual element and submits and other is user clicks select all button and submits so that, on the user's requirement, I want to fetch the item's details in the controller. Please help me out.

here is my code

HTML

        <div ng-repeat="item in vm.items">
          <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 >
          <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 ></td>
                <td ></td>
                <td ></td>
            </tr>
            </tbody>

        </table>
     </div>

Controller

 vm.purchaseItems = purchaseItems;

  function purchaseItems(item) {
  console.log(item); 
// I want to log only selected items either single or all based on user call
}

Should I go with a directive or can it be done simply in the controller itself need a suggestion




Aucun commentaire:

Enregistrer un commentaire