My web app has tons of controller and JS stuff included. So checkbox always show false state. But when I give delay for initialization it works well.
function initializeSwitch() {
$timeout(function() {
// Remove any old switcher
if (switcher) {
angular.element(switcher.switcher).remove();
}
// (re)create switcher to reflect latest state of the checkbox element
switcher = new $window.Switchery(elem[0], options);
var element = switcher.element;
element.checked = scope.initValue;
if (attrs.disabled) {
switcher.disable();
}
switcher.setPosition(false);
element.addEventListener('change',function(evt) {
scope.$apply(function() {
ngModel.$setViewValue(element.checked);
})
});
scope.$watch('initValue', function(newValue, oldValue) {
switcher.setPosition(false);
});
}, 200); // <-- changed value 0 to 200
}
My web app has tons of controller and JS stuff included. So checkbox always show false state. But when I give delay for initialization it works well.