2015-11-02 70 views
0

我正在使用我的第一個Angular網站,並且所有的工作都順利進行。第二個頁面應該出現並取代第一,當遇到與NG-顯示設置的情況下,HTML代碼如下不能讓ng-hide和ng-show工作

<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這組消息爲null的功能我控制器gameController.js - $ scope.startGame = function(){ $ scope.message =「」; } 我期待當消息設置爲空,我的第一頁會隱藏,第二個會替換它,但沒有任何反應,請有人請告訴我爲什麼。

+0

你設置消息'。這是一個空字符串,不認爲是一樣的空... – JasperZelf

回答

1

您正在將消息設置爲空字符串,然後測試爲空。

你需要測試一個空字符串:

<div ng-show="message != ''"> 

或者設置消息爲null:

$scope.startGame = function() { $scope.message = null; } 
+0

是的,將它設置爲空作業,謝謝 – user616076