0

I have situtation like this:

<a ng-click="doSomething()">
   Text
   <input type="checkbox"/>
</a>

And if I want to mark the checkbox it does doSomething() instead and checkbox remains unchecked. I know that it is easy to say to just put outside but I really can't do it so don't offer that.

Thanks in advance!

0

2 Answers 2

1

How about:

<a ng-click="doSomething()">
   Text
   <input type="checkbox" ng-checked="boxChecked" />
</a>

Then in your $scope.doSomething() function add an assignment $scope.boxChecked = true.

Sign up to request clarification or add additional context in comments.

2 Comments

Good answer! Almost solves my problem but in your case the checkbox gets checked also if I click on the Text. Is there a way to check the checkbox only when I click on the checkbox?
@RVstack oh haha, then how about you do <input type="checkbox" ng-checked="boxChecked" ng-click="checkTheBox()" />, and move that assignment $scope.boxChecked = true from $scope.doSomething() into $scope.checkTheBox()
0

You can toggle input by follwoing way:

<!--temlate-->
<a ng-click="doSomething()">
   Text
   <input type="checkbox" ng-checked="myModelProperty"/>
</a>

//controller
$scope.doSomething = function(){
  $scope.myModelProperty = !$scope.myModelProperty;
}

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.