visibility hidden in AngularJs?

后端 未结 7 2181
南笙
南笙 2021-02-03 16:45

ng-show applied display: none

7条回答
  •  梦如初夏
    2021-02-03 17:05

    Here's a simple directive that sets the visibility to hidden or visible (but not collapse):

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

    Usage:

    
    

    angular.module('MyModule', [])
    
    .directive('visible', function() {
    
      return {
        restrict: 'A',
        
        link: function(scope, element, attributes) {
        	scope.$watch(attributes.visible, function(value){
        	  element.css('visibility', value ? 'visible' : 'hidden');
            });
        }
      };
    })
    
    .controller('MyController', function($scope) {
      $scope.showButton = true;
    });
    
    
    
    

提交回复
热议问题