AngularJS directive to set visibility of html element

Standard

The visibility property specifies whether an element’s content is visible or not. Its values can be visible, hidden, collapse, and inherit. The default value is inherit. If visibility is set to visible, the element displays normally. If visibility is set to hidden, the element’s content is hidden (but transparent), but the element still takes up the same location of its generated box. If visibility is set to collapse and the element is not a row or column, according to the CSS2 specification, collapse should have the same meaning as hidden. Firefox does this correctly, but IE6 and IE7 do not treat collapse as hidden.

app.directive('visible', function() {
        return {
            restrict: 'A',
            link: function(scope, element, attributes) {
                scope.$watch(attributes.visible, function(value) {
                    element.css('visibility', value ? 'visible' : 'hidden');
                });
            }
        };
    });
Advertisements