Created
May 28, 2013 09:29
-
-
Save gaelbillon/5661596 to your computer and use it in GitHub Desktop.
could be useful in case of eg: websockets pushing data that can randomly be defined or undefined, if the new value coming in is undefined, this directive keep the old value displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp.directives', []). | |
directive('keepoldvalueifnewisempty', function() { | |
return { | |
restrict: "E", | |
link: function(scope, elm, attrs) { | |
scope.$watch(attrs.val, function (newValue, oldValue) { | |
newValue = !newValue ? oldValue : newValue; | |
elm.html(newValue); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment