Home > Web Front-end > HTML Tutorial > ng-show in angularjs not working? _html/css_WEB-ITnose

ng-show in angularjs not working? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:49:25
Original
2248 people have browsed it

Paste the code first

<html ng-app>	<body>		<div ng-controller="DeathrayMenuController">			<button ng-click='toggleMenu()'>isShow</button>				<ul ng-show="menuState.show">				<li >zero</li>					<li >one</li>				<li >two</li>					</ul>			</div>							<script src="angular.js"></script>		<script>			function DeathrayMenuController($scope){				$scope.menuState.show=false;				$scope.toggleMenu=function(){					$scope.menuState.show=!$scope.menuState.show;				}			};		</script>	</body></html>
Copy after login


The original intention is to click the button to display or hide the ul list. I don’t know what went wrong. I've only been learning this for 2 days and looked it up online. I really don’t know much about it, please help me.


Reply to the discussion (solution)

Debug it and look at the actual html. It is estimated that other tags are nested, so show and hide may not be valid! !

Debug it and see the actual html. It is estimated that other tags are nested, so show and hide may not be valid! !



Thank you! After debugging, I found that menuState is undefined. Adding this code can display and hide it normally
$scope.menuState={};
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template