2

I want to disable a checkbox input, I mean, the user can not check de checkbox

there is an atribute to disable this? like [enable] or [disable]? or how can I fix this?

<input type="checkbox" name="isActive"  [(ngModel)]="user.isActive">

any idea?

3
  • 1
    The disabled attribute is probably what you're looking for...were you looking to bind that to an event? Commented Apr 19, 2017 at 16:13
  • @Makoto You should write that as an answer, not a comment. Commented Jul 6, 2017 at 19:57
  • 1
    @Kody: Since I'm asking a question to the OP...no, I really shouldn't leave that as an answer. Commented Jul 6, 2017 at 20:21

3 Answers 3

1

To disable a checkbox, I tried many [disabled], [attr.disabled]

But interpolation worked.

<input name="chkUpdate" type="checkbox" 
       [(ngModel)]="selectedGrp.Updateind" 
       disabled="{{selectedGrp.App_Id == 5}}"/>
Sign up to request clarification or add additional context in comments.

Comments

1

Interpolation didn't work for me, had to set disabled on FormControl:

new FormControl({value: value, disabled: true});

Comments

1

If you are using reactive forms, you can use something like this in the right methods:

To disable:

this.myform.controls['chkUpdate'].disable();

To enable:

this.myform.controls['chkUpdate'].enable();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.