我认为这是Bootstrap 3的一个问题,没有官方修复程序,但Bootstrap 4没有提及。
数据切换用于单选输入,当数据切换在输入上时,AJS模型不会更新,但没有更新。 加上一个额外的问题,即如果我不使用数据切换,则不会将切换影响应用于所选的单选选项。
<html ng-app="testApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<!--ISSUE SCRIPT - data-toggle -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://code.angularjs.org/1.4.0/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-messages.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="testController">
<form>
<!-- YES/NO -->
<div class="form-group required">
<label class="input-label">Do you have any debt?</label>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary">
<input type="radio" name="HasDebt" autocomplete="off"
ng-value="true"
ng-model="User.HasDebt"> Yes
</label>
<label class="btn btn-secondary">
<input type="radio" name="HasDebt" autocomplete="off"
ng-value="false"
ng-model="User.HasDebt"> No
</label>
</div>
</div>
Value: {{User.HasDebt}}
</form>
</body>
</html>
答案 0 :(得分:1)
您使用的AngularJS版本似乎与jQuery不兼容。请用最新版本替换它。以下是index.html文件:
<!DOCTYPE html>
<html ng-app="testApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- JS -->
<!--ISSUE SCRIPT - data-toggle -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-messages.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="testController">
<form>
<!-- YES/NO -->
<div class="form-group required">
<label class="input-label">Do you have any debt?</label>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary">
<input type="radio" name="HasDebt" autocomplete="off"
ng-value="true"
ng-model="User.HasDebt"> Yes
</label>
<label class="btn btn-secondary">
<input type="radio" name="HasDebt" autocomplete="off"
ng-value="false"
ng-model="User.HasDebt"> No
</label>
</div>
</div>
Value: {{User.HasDebt}}
</form>
</body>
</html>
希望有帮助。