Hamed
Hamed

Reputation: 410

How to check if checkbox is checked in Angular JS?

I have HTML form with fields: input, textarea. All fields have attribute required and submit button have:

<div ng-click="Share()" ng-disabled="shareForm.$invalid"</div>

How I can check if checkbox is checked or not and disable button?

Upvotes: 1

Views: 6414

Answers (2)

freethinker
freethinker

Reputation: 2435

Put ng-model binding on your input:

<div ng-click="Share()" ng-model="checked" ng-disabled="shareForm.$invalid"</div>

And inside your "Share" function:

if($scope.checked){
   //do some action if checkbox is checked
}

Upvotes: 3

tektiv
tektiv

Reputation: 14187

Use "ng-model" in angular

<input type="checkbox" ng-model="checked"/>
<button ng-disabled="!checked"> MyInput </button>

Upvotes: 3

Related Questions