0

I need to map a list of a selected checkbox to an javascript (AngularJS) array. When the user select one checkbox I need to update the related array. This array must have this structure:

$scope.items = ["value specific selected checkbox1", "value specific selected checkbox2"]

I use ng-true-value directive in my input tag to set a specific value of a selected checkbox to add to items array.

If the user unselect one checkbox I need to remove the specific value from items array. The array should not have duplicate values.

2
  • Hmmm... I am missing some code to see what have you done already and where you got stuck... Commented Feb 19, 2015 at 12:57
  • I need to write the logic to map a group of checkboxes into my items array. Commented Feb 19, 2015 at 13:19

1 Answer 1

0

Look at this: https://github.com/vitalets/checklist-model

Otherwise, you can create your own directive which would use the ngModelController of your checkbox ($formatters and $parsers):

  • Formatter: your model is an array, you return true or false depending if the value of your checkbox is inside this array.
  • Parser: if it is checked, you add your checkbox value to the array, otherwise you remove it.

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.