Cómo saber si la casilla de verificación está marcada o no dentro de ng-repeat y cómo usar ng-model para la casilla de verificación
Debajo de json se usará en `ng-repeat.
[
{
"categoryId": 1,
"categoryName": "Men",
"subCategory": [
{
"subCategoryId": 1,
"subCategoryName": "Footwear"
},
{
"subCategoryId": 3,
"subCategoryName": "Cloths"
}
]
},
{
"categoryId": 2,
"categoryName": "Women",
"subCategory": [
{
"subCategoryId": 2,
"subCategoryName": "Footwear"
}
]
},
{
"categoryId": 3,
"categoryName": "Kids",
"subCategory": []
}
]
Debajo del código tiene dosng-repeat
y mostrando datos de json anteriores.
<ul class="list-unstyled" ng-repeat="cat in catSubCat">
<li>
<label>
<input type="checkbox" name="categories" id="category_{{cat.categoryId}}" ng-model="categoryChk" ng-change="categoryCheckBox(cat.categoryId, $index)" readonly><span class="gap">{{cat.categoryName}}</span>
</label>
<ul class="list-unstyled" ng-repeat="subCat in cat.subCategory">
<li>
<label>
<input type="checkbox" name="subcategories" id="sub_category_{{subCat.subCategoryId}}" ng-model="subCategoryChk" ng-change="subCategoryCheckBox(cat.categoryId, subCat.subCategoryId, $index)"><span class="gap">{{subCat.subCategoryName}}</span></label>
</li>
</ul>
</li>
</ul>
En este código, intento consolar los modelos para verificar si la casilla está marcada o no
$scope.subCategoryCheckBox = function(catId, subId, index) {
console.log($scope.subCategoryChk);
}
$scope.categoryCheckBox = function(catId, index) {
console.log($scope.categoryChk);
}
Estoy tratando de verificar si la casilla de verificación está marcada o no dentro$scope.subCategoryCheckBox()
y$scope.categoryCheckBox()
imprimiendo el modelo en la consola. Pero está mostrandoundefined
en consola