0

I have an array of checkboxes coming from a collection.

See below:

<div class="form-group">
    Select days in a week :
    <td class="even" *ngFor="let item of dayList">
    <input value="{{item.check}}" type="checkbox" checked="item.check" formControlName = "selectedDays">  {{item}}
   </div>

formControlName I am set as selectedDays.

I need to generate JSON object for the selected checkbox values.

Currently, i am getting boolean value in selectedDays. But I am supposed to get an array of checked values in an array inside JSON object.

this.dayList = ['Sun', 'Mon', 'Tue','Wed',"Thu","Fri","Sat"];

JSON Object looks like below, please note the value of selectedDays, it is supposed to be "Sun, Mon" based on selection, but it is showing as true.

 Object
    date
    :
    "2"
    day
    :
    "Mon"
    hour
    :
    "3"
    minute
    :
    "3"
    schedulerjobtype
    :
    "Daily"
    selectedDays
    :
    true
    useCase
    :
    "UC 2"
    zone
    :
    "Zone 3"

How can I implement this?

3
  • any idea why downvoted? Commented Jun 4, 2018 at 12:32
  • can you post dayList array as well??? Commented Jun 4, 2018 at 12:49
  • updated question Commented Jun 4, 2018 at 12:52

1 Answer 1

0

Use [(ngModel)] in place of value

 <input [(ngModel)]="item.check" type="checkbox" checked="item.check" formControlName = "selectedDays">
Sign up to request clarification or add additional context in comments.

1 Comment

this is showing the checkboxes now, but still, the JSON object value shows true, i am expecting array or comma separated values.

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.