0

This is a small piece of code which has been written by me and thought it may help some one who are looking for similar functionality:

custom directives on li elements - clicking on which they select/unselect the li element and yields the selected objects in an array (can be collected under controller)

    <div ng-app="myApp" ng-controller="myCtrl">

  <ul>
    <li>
      <input type="text" ng-model="search_ms.title" />
    </li>
    <li 
    ng-repeat="x in items | filter:search_ms" 
    multi-select multi-select-item="x" 
    ng-class="{selected:x.checked}" 
    ng-click="getAllSelectedItems(items)">
      {{x.title}} --> {{x.checked}}
    </li>
  </ul>

  <ul>
    <li>
      <input type="text" ng-model="search_ss.title" />
    </li>
    <li 
    ng-repeat="x in items_ | filter:search_ss" 
    single-select 
    single-select-item="x" 
    unselect-all-items="items_" 
    ng-class="{selected:x.checked}" 
    ng-click="getAllSelectedItems(items_)">
      {{x.title}} --> {{x.checked}}
    </li>
  </ul>

<div class="clearfloat">
</div>


  <br/>
  <br/>
  <br/>

  <p>
  {{selectedItems}}
  </p>

  <br/>
  <br/>
  <br/>

  <p>
  {{unselectedItems}}
  </p>

JS Fiddle: http://jsfiddle.net/AjayBunga/NBhn4/230/

Both single select (like radios) and multi select (like checkboxes) has been implemented. Please suggest if I can optimise any code or if can be done in much simpler way as I am new to angular directives.

Thanks in advance.

1 Answer 1

0

instead of using ng-click and capturing the changes with a timeout

this answer helped me in writing a dircetive callback function

AngularJS Directive Callback

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.