This has come up while I was trying to change the back color of a li
whenever the text changes. From another post I was directed to, I found a method of doing this which looks ideal, and have added to my plunker example.
So, the main bit of code here is in this directive...
.directive('animateOnChange', function ($timeout) {
return function (scope, element, attr) {
scope.$watch(attr.animateOnChange, function (nv, ov) {
if (nv != ov) { // change to true and this works
element.addClass('changed');
$timeout(function() {
element.removeClass('changed');
}, 500); // Could be enhanced to take duration as a parameter
}
});
};
})
When you click the button, a property is updated, but we get no color change, as the values of nv
and ov
at the line if (nv != ov)
are always the same (if you replace the nv != ov
with just true
we can see the color change, which also then occurs at initialisation, which I don't really want.
So the question is why would my old value and new value (ov, nv) always be the same?
Any help greatly appreciated.