Javascript AngularJS复选框取消选中
当复选框被取消选中时,表单数据将被重置Javascript AngularJS复选框取消选中,javascript,angularjs,Javascript,Angularjs,当复选框被取消选中时,表单数据将被重置 <div class="form-group"> <input type="text" verify-store ng-model="user.merchant_store_name" class="form-control" name="merchant.store_name" placeholder="Store Name" ng-model-options="{ updateOn: 'bl
<div class="form-group">
<input type="text" verify-store ng-model="user.merchant_store_name" class="form-control" name="merchant.store_name" placeholder="Store Name" ng-model-options="{ updateOn: 'blur' }" required>
<div ng-if="signupForm.$pending.usernameExists">verifying....</div>
<div ng-if="signupForm.$error.usernameExists[0].$viewValue">
<label class="control-label" style="color:red">A store with that name already exists. Please select another name.</label>
</div>
<div class="form-group">
<input type="text" class="form-control" ng-model="user.merchant_mobile_phone" placeholder="Phone" >
</div>
</div>
<div class="checkbox clip-check check-primary">
<input type="checkbox" id="agree" ng-model="signupForm.agree" value="agree" ng-required="!signupForm.agree">
<label for="agree">I agree</label>
</div>
<div class="checkbox clip-check check-primary" ng-show="signupForm.agree">
<input type="checkbox" id="merchant" ng-model="signupForm.merchant" value="merchant" >
<label for="merchant">Sign up as merchant</label>
</div>
验证。。。。
具有该名称的存储已存在。请选择其他名称。
我同意
注册成为商人
是否有一种方法可以在视图模板内完成此操作,而不是将其传递给控制器。或者我应该为此写一个指令
谢谢 使用以下两个DOM设置,您不必在控制器中写入一行代码即可完成任务
<input type="text" ng-model="myText">
<input type='checkbox' ng-model='chkMonitor' ng-click='!chkMonitor && (myText = "")' >
只要
chkMonitor
为false,您的myText=”“
就永远不会执行 最简单的方法是只重置模型。@dfsq有一个选项,如果用户选中复选框,将显示额外的div
,并且用户必须填写信息,则取消选中将隐藏div,但不会重置数据,这就是为什么我再次选中时表单仍无法清除的原因<代码>点击='!signupForm.merchant&(user.merchant\u store\u name=“”)”这里有一把小提琴演示了这段代码。
ng-click='!chkMonitor && (myText = "")'