如何在angularjs中停止绑定

时间:2014-11-03 05:15:45

标签: angularjs angularjs-directive

我有一个复选框,模型status.useJoin也绑定了div



<input type="checkbox"  ng-model="status.useJoin"  ng-click="toggleJoin($event);" >

 <div ng-if="status.useJoin"> show area</div>
&#13;
&#13;
&#13;

status.useJointrue时,会显示div

我的问题是,当我想阻止复选框的默认操作时。我会像这样编写函数toggleJoin

&#13;
&#13;
  $scope.toggleJoin = function (dimension,$event) {
   if (status.useJoin) {
      $event.preventDefault();
      return; 
   }
 }
&#13;
&#13;
&#13;

复选框操作已停止,但仍会修改status.useJoin。我怎么能阻止绑定?

1 个答案:

答案 0 :(得分:1)

您可以使用ng-disabled指令

<input type="checkbox"  ng-model="status.useJoin"  ng-disabled="onYourDisableCondition();" >


$scope. onYourDisableCondition = function () {
   if (status.useJoin) { //Add your additional conditions     
      return true; 
   }
 }