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

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

WBOY
WBOYOriginal
2016-06-24 11:49:252203browse

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>


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={};
Statement:
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