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

One thought on “AngularJS directive to set visibility of html element

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s