大家好我的代码在单击ng-click切换复选框时工作正常,如果复选框未选中,则可以在输入标记中输入数字时进行检查< / strong>通过$ scope。$ watch()。但是当我在输入数字后点击“toggleCheckBox()”以取消选中“购物”标签的CheckBox时,ng-class无效。 $ scope。$ watch()显示“Hello World!”但没有初始化$ scope.checkShopping = true;可能是什么问题呢? 这是代码。非常感谢你!
$scope.toggleCheckbox = function (mainModel, subModel) {
var index = $scope[mainModel].indexOf(subModel);
if (index >= 0) {
$scope[mainModel].splice(index, 1);
} else {
$scope[mainModel].push(subModel);
}
};
$scope.$watch('Shopping',function(){
if($scope.Shopping > 0){
$scope.checkShopping = true; //this code is not working on 2nd input. The ng-class is not setting to 'TRUE'
console.log("Hello world!");
}
});
.checkListHolder {
width: 100%;
display: block;
overflow: hidden;
}
.checkListHolder > li {
display: inline-block;
width: 100%;
float: left;
overflow: hidden;
padding: 5px 0;
}
.checkedListItem .checkboxList {
background-image: url(../images/form-icons/checkbox-on.png);
}
.checkboxList {
width: 20px;
height: 20px;
background-repeat: no-repeat;
background-position: center;
background-image: url(../images/form-icons/checkbox-off.png);
margin: 0 10px 0 0;
cursor: pointer;
}
.checkboxLabel {
width: auto;
float: left;
overflow: hidden;
color: #FFF;
font-size: 14px;
font-family: "Open Sans", sans-serif!important;
}
<li ng-class="{checkedListItem : checkShopping == true}">
<div class="checkboxList" ng-click="toggleCheckbox('PleasureVacationList','Shopping')"> </div>
<div class="checkboxLabel">Shopping</div>
</li>
<li>
<input type="number" ng-model="Shopping">
</li>
可能是什么问题?谢谢你的帮助
答案 0 :(得分:1)