Skip to content

Instantly share code, notes, and snippets.

@rolaveric
Created February 4, 2014 22:27
Show Gist options
  • Save rolaveric/8813637 to your computer and use it in GitHub Desktop.
Save rolaveric/8813637 to your computer and use it in GitHub Desktop.
A simplified implementation of the ng-hide directive, to illustrate directive testing.
angular.directive('ngHide', [function () {
return function (scope, element, attr) {
scope.$watch(attr.ngShow, function ngHideWatchAction(value){
// Call "addClass()" or "removeClass()" based on the attribute value
// AngularJS already declares the CSS for the "ng-hide" class
element[value ? 'removeClass' : 'addClass']('ng-hide');
});
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment