0

I have a multiple checkbox list in my page.

<label class="each-topic each-hcp" for="hcp{{hcpinfo.id}}{{hcpinfo.firstName}}" *ngFor="let hcpinfo of hcplist; let i=index">
    <input type="checkbox" name="hcpid" id="hcp{{hcpinfo.id}}{{hcpinfo.firstName}}" value="{{hcpinfo.id}}">
    <h4>{{hcpinfo.firstName}}</h4>
</label>

In my .ts file I have a predefined array as this.hcparr.

This contains values like [5,8,10] - as array.

If hcparr has hcpinfo.id value then the corresponding checkbox needs to be selected.

How do you implement the if condition with multiple check box with this array list?

Please help me.

1
  • try adding up a plunker to your question. Commented Aug 10, 2018 at 6:18

1 Answer 1

1

Use checked binding:

 <label class="each-topic each-hcp"  *ngFor="let hcpinfo of hcplist; let i=index" >                
  <input type="checkbox" name="hcpid" id="hcp{{hcpinfo.id}}{{hcpinfo.firstName}}" value="{{hcpinfo.id}}" [checked]="hcparr.indexOf(hcpinfo.id) > -1" >
  <span>{{hcpinfo.firstName}}</span>          
 </label>

Demo

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.