<a> with ng-click

时间:2016-05-10 17:16:58

标签: html angularjs

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!

2 个答案:

答案 0 :(得分:1)

怎么样:

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

然后在$scope.doSomething()函数中添加作业$scope.boxChecked = true

答案 1 :(得分:0)

您可以通过以下方式切换输入:

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

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