我在一个 Angular 应用程序中使用iCheck,当选中时我有一个基本的复选框显示图像。这与 ng-show 完美配合,但是当我在 Controller 中将值设置为 true 时,加载页面时不会返回选中状态。
Controller
$scope.basicIntake = {};
$scope.basicIntake.insurance_cover = true;
html
<div class="row">
<div class="form-group col-lg-6">
<div class="col-lg-12">
<label>
<input icheck type="checkbox" ng-model="basicIntake.insurance_cover">
click to see image
</label>
</div>
</div>
<div class="form-group col-lg-6">
<div class="col-lg-12">
<img ng-src="http://i.imgur.com/vkW3Lhe.jpg" class="img-responsive img-thumbnail" ng-show="basicIntake.insurance_cover">
</div>
</div>
</div>
最佳答案
这是因为您的模板未使用指令 ng-controller
绑定(bind)到任何 Controller 。
在您创建任何事件之前,您的属性不会被创建。就像:点击
。
请参阅附件 fiddle并尝试连接。
尝试从顶部 Div
中删除 ng-controller
来解决您的问题。
此外:当您已经拥有 ng-model
时,就无需再进行 ng-checked
关于javascript - 将值设置为 true 时,复选框不显示已选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43279998/