stackattack
stackattack

Reputation: 354

Input checkbox in <a> with ng-click

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!

Upvotes: 0

Views: 321

Answers (2)

Anton Strogonoff
Anton Strogonoff

Reputation: 34032

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.

Upvotes: 1

shershen
shershen

Reputation: 9993

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;
}

Upvotes: 0

Related Questions