SoFunction
Updated on 2025-04-09

Talk about hiding and showing in AngularJs

AngularJS extends HTML with new properties and expressions.

AngularJS can build a single page application (SPAs: Single Page Applications).

The code looks like this:

<!DOCTYPE html>
<html ng-app="a2_12">
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="../js/angularJs-1.2."></script>
<style type="text/css">
body{
font-size: 12px;
}
ul{
list-style-type: none;
width: 408px;
margin: 0px;
padding: 0px;
}
div{
margin: 8px 0px;
}
</style>
</head>
<body>
<div ng-controller="c2_12">
<div ng-show="{{isShow}}">Tao Guorong</div>
<div ng-hide="{{isHide}}">1012@</div>
<ul ng-switch on={{switch}}>
<li ng-switch-when="1">11111111111111111</li>
<li ng-switch-when="2">22222222222222222</li>
<li ng-switch-default>33333333333333333</li>
</ul>
</div>
<script type="text/javascript">
var a2_12 = ('a2_12', []);
a2_12.controller('c2_12', ['$scope', function($scope) {
$=true;
$=false;
$=2;
}]);
</script>
</body>
</html> 

The function of the ng-switch directive is to display the elements that match successfully. This directive needs to be used in combination with the ng-switch-when and ng-switch-default directives.
When the specified on value matches one or more elements that add the ng-switch-when directive, these elements are displayed, hiding of the unmatched elements.
If no element matching the on value is found, the element with the ng-switch-default directive added is displayed.

The above is the hidden and displayed content in AngularJs introduced to you in this article. I hope you like it.