Questions And Answers

More Tutorials

Angular ngShow and ngHide

The ng-show directive shows or hides the HTML element based on if the expression passed to it is true or false. If the value of the expression is falsy then it will hide. If it is truthy then it will show.

The ng-hide directive is similar. However, if the value is falsy it will show the HTML element. When the expression is truthy it will hide it.

Working JSBin Example

var app = angular.module('app', []);
 .controller('ExampleController', ExampleController);
function ExampleController() {
 var vm = this;
 //Binding the username to HTML element
 vm.username = '';
 //A taken username
 vm.taken_username = 'StackOverflow';


<section ng-controller="ExampleController as main">
 <p>Enter Password</p>
 <input ng-model="main.username" type="text">
 <!-- Will always show as long as StackOverflow is not typed in -->
 <!-- The expression is always true when it is not StackOverflow -->
 <div style="color:green;" ng-show="main.username != main.taken_username">
 Your username is free to use!
 <!-- Will only show when StackOverflow is typed in -->
 <!-- The expression value becomes falsy -->
 <div style="color:red;" ng-hide="main.username != main.taken_username">
 Your username is taken!
 <p>Enter 'StackOverflow' in username field to show ngHide directive.</p>


In this page (written and validated by ) you learned about AngularJS ngShow and ngHide . What's Next? If you are interested in completing AngularJS tutorial, your next topic will be learning about: AngularJS ngRequired.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.