Angular JS (Angular 1.x) :

The [hidden] attribute is not natively supported as a built-in directive in AngularJS (Angular 1.x). Instead, AngularJS provides directives like ng-show, ng-hide, and ng-if for conditional rendering, allowing you to dynamically control the visibility of HTML elements based on expressions.

Let’s explore each of them:

1. ngHide and ngShow Directives:

Both ngHide and ngShow evaluate expressions, when the expression is true, ngHide hides the element, and ngShow shows the element.

ngHide

The ngHide directive is used to conditionally hide an element based on an expression. When the expression evaluates to true, the element is hidden; otherwise, it is shown

ngShow

The ngShow directive is used to conditionally show an element based on an expression. When the expression evaluates to true, the element is displayed; otherwise, it is hidden.

JS:

var app = angular.module('myApp', []);
app.controller('MyController', function($scope) {
  $scope.isHidden = true; // Initially hide the input tag 
  $scope.isVisible = true; //  Initially show the input tag
}

-> $scope.isHidden is initially set to true, so the input field with ng-hide is hidden when the page loads.

-> $scope.isVisible is initially set to true, so the input field with ng-show is visible when the page loads.

2. ngIf Directive:

Angular Js also has the ngIf directive, which removes or recreates the element based on a condition, it’s used for more fine-grained control of rendering.

.

The input tag will be displayed when the expression isDisplayed is true.

Angular (2 and above) :

In Angular, ngHide, ngShow, and [hidden] are not directly available as built-in directives. Instead, Angular relies on the ngIf directive for conditional rendering and [hidden] for toggling visibility.

1. ngIf Directive:

Angular utilizes the ngIf directive for conditional rendering. The ngIf directive adds or removes elements from the DOM based on a provided expression. When the expression evaluates to true, the element is added to the DOM; otherwise, it is removed.

Content to be rendered conditionally
the content inside the
is rendered only when the condition is true.

2. [hidden] Attribute:

While [hidden] is a standard HTML attribute that hides elements in regular HTML, in Angular, it is often used for toggling visibility. However, it is important to note that it does not provide the same flexibility as ngIf for conditional rendering.

Content to be hidden or shown based on isHidden

[hidden] can be used for simple visibility toggling, but it does not alter the DOM structure like ngIf.

Support On Demand!

Angular