Como saber a caixa de seleção marcada ou não dentro do ng-repeat e como usar o ng-model para a caixa de seleção
Abaixo, o json usará no `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": []
}
]
O código abaixo tem doisng-repeat
e mostrando os dados acima de json.
<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>
Neste código, estou tentando consolar os modelos para verificar se a caixa de seleção está marcada ou não
$scope.subCategoryCheckBox = function(catId, subId, index) {
console.log($scope.subCategoryChk);
}
$scope.categoryCheckBox = function(catId, index) {
console.log($scope.categoryChk);
}
Estou tentando verificar se a caixa de seleção está marcada ou não dentro$scope.subCategoryCheckBox()
e$scope.categoryCheckBox()
imprimindo o modelo no console. Mas está mostrandoundefined
no console.