http://plnkr.co/edit/VAE43y5cagCF8jq5AlaY?p=preview
Within the directive, I'm using scope.$apply(). However, if you click too quickly it changes the value but not the visual affect. This problem seems to be related to timing. If I load the page and let it sit for 2 seconds the first click changes the value. However, if I try to click it too quickly, it'll change the value without changing the visuals.
Can anyone explain this? I'm thinking it might be mid-digest cycle or something like that, but can't say for sure and I'm not sure what to do about it...
//toggle the state when clicked
el.bind('click', function () {
scope.$apply(function () {
var getter=$parse(attrs.ngModel);
var setter=getter.assign;
setter(scope,!getter(scope));
//scope[attrs.ngModel] = !scope[attrs.ngModel];
if (el.hasClass('on')) {
off();
} else {
on();
}
});
});