我正在开发我的第一个 Angular 网站,首页一切进展顺利。当满足 ng-show 设置的条件时,应该出现第二个页面并替换第一个页面,html 代码如下
<body ng-controller="gameController">
<div class="container">
<div ng-hide="message == null">
<div class="row clearfix">
<div class="col-md-12 column">
<h2>
<img ng-src="{{headerSrc}}" style="width: 300px; height: 250px" />
</h2>
<h3>
{{ message }}
</h3>
.
.
.
<div class="form-group">
<button id="startBttn" style="color:white;background-color:green;width:200px;height:45px" ng-click="startGame()">Start Game</button>
</div>
</form>
</div>
</div>
</div>
<div ng-show="message == null">
<form name="frmPlayGame" validate class="form-inline">
当按下 startBttn 时,它会运行 startGame,它在我的 Controller gameController.js 的函数中将消息设置为 null - $scope.startGame = 函数 () { $scope.message = ""; } 我原以为当消息设置为 null 时,我的第一个页面将隐藏,第二个页面将替换它,但没有任何反应,有人可以告诉我原因吗。
最佳答案
您正在将消息设置为空字符串,然后测试是否为空。
您需要测试空字符串:
<div ng-show="message != ''">
或者将消息设置为空:
$scope.startGame = function () { $scope.message = null; }
关于javascript - 无法让 ng-hide 和 ng-show 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33479156/