AngularJS ng-hide – conditionally hide an element

AngularJS directive ng-hide hides an element if the expression ng-hide evaluates to true. Under the hood it adds or removes class ng-hide to the element. The .ng-hide CSS class is predefined in AngularJS and sets the display style to none (using an !important flag).

<div ng-app="myApp" ng-controller='MyCtrl'>
  <label>Select checkbox to hide: <input type="checkbox" ng-model="doHide"></label><br/>
  <span ng-hide="doHide"><strong>Hide this text</strong></span>
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script>
  var module = angular.module('myApp', []);
  module.controller('MyCtrl', function($scope) {});
</script>
refresh
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments