'Check if checkbox needs to be checked with a callback function
I want to check if a checkbox element needs to be checked with a callback and set the attribute accordingly. (Angular v1.4.7)I use ng-init to set the state but it is not setting the checks to "checked" cuurently. Any hints?
angular.module('vpWidgets', ['ui.bootstrap', 'ngSanitize'])
.controller('ShiftWidgetCtrl', function($scope) {
$scope.isInCookie = function(item){
return true
}
})
<label class="filter" ng-repeat="country in countries">
<input id="filter-{{ country.slug }}" type="checkbox" value="{{ country.name }}"
ng-click="toggleCountryAndArea(country.slug)"
ng-class="{ 'country': selectedCountryAndArea.indexOf(country.slug) > -1 }"
ng-init="isChecked = isInCookie(country)" [checked]="isChecked">{{ country.name }}
</label>
Solution 1:[1]
got it myself. I needed to use ng-checked.
<label class="filter" ng-repeat="country in countries">
<input id="filter-{{ country.slug }}" type="checkbox" value="{{ country.name}}
ng-click="toggleCountryAndArea(country.slug)"
ng-class="{ 'country': selectedCountryAndArea.indexOf(country.slug) > -1 }"
ng-checked="isInCookie(country)">{{ country.name }}
</label>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jurudocs |
