1

https://www.primefaces.org/primeng/#/checkbox

In the below code I am trying to get the checkboxes to add objects to an array that is in model driven form with the variable name of selectedComponents.

So the object type of item1 below is CampaignProductModel and that is an array called selectedComponents in my model for the form.

I am having trouble binding and added of all checked items to the array in my model object.

 <p-dataTable *ngIf="perviousCampaignProduct" [value]="perviousCampaignProduct" #dt [responsive]="true" filter="filter" [rows]="25" [paginator]="true" selectionMode="single" [(selection)]="selectedItem" [contextMenu]="cm">
    <p-header>Pervious Campaign Products </p-header>
    <p-column header="Images">
        <template let-item="rowData" pTemplate="body">
          <img style="max-height:150px;" src="http://cdnll.somesite.com/images/1000/{{item.itemSku}}.jpg" />
        </template>
    </p-column>
    <p-column field="itemSku" header="Item" [filter]="true" filterMatchMode="contains" filterPlaceholder="Search"></p-column>
    <p-column field="components" header="Components">
       <template let-item="rowData" let-col pTemplate="body">
          <ul style="list-style: none;">
             <li *ngFor="let item1 of item[col.field]">
                <p-checkbox value="item1" formControlName="selectedComponents" label="{{item1.itemSku}}"></p-checkbox>
             </li>
          </ul>
       </template>
     </p-column>
  </p-dataTable> 

Goal

Added all check items from p-checkbox as objects to an array in my model driven form.

Tried:

value="{{item1}}"

... knew it won't work

1 Answer 1

2

It´s a bit later but i think this can resolve your problem Change this code:

 <p-checkbox value="item1" formControlName="selectedComponents" label="{{item1.itemSku}}"></p-checkbox>

for this one:

 <p-checkbox [value]="item1" formControlName="selectedComponents" [label]="item1.itemSku"></p-checkbox>
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.