2017-05-11 120 views
0

我的表格有文本輸入字段,當頁面加載時它應該隱藏,並且當我點擊它們時出現。這是我所嘗試過的,並且不起作用。但是反過來,我可以讓場地消失,當我點擊它。我希望表格有隱藏的輸入字段,只有當我點擊它們時纔會出現

<div class="container-fluid"> 
    <table id="sampleGrid" class="table"> 
     <thead> 
      <tr> 
       <th>Fat (Z10006)</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td><input type="text" class="col-xs-8" name="Fat" ng-if="visible" ng-click="hidden()"></td> 
      </tr> 
     </tbody>  
    </table> 
</div> 

var sampleApp =angular.module('sampleApp',[]); 
    sampleApp.controller('gridController',function($scope,$http) { 
    $scope.visible = false; 
    $scope.hidden = function() { 
     $scope.visible = true; 
    }; 
    }) 
+2

如何點擊隱藏的輸入欄? :-) – cjs1978

+0

因此,無論如何要實現這一功能,我希望字段只出現在我打算。 – shafeerambatt

回答

0

的小變化是進行。 ng-click應該位於內部,以便單元出現在點擊位置。

<td ng-click="hidden()"><input type="text" class="col-xs-8" name="Fat" ng-if="visible"></td> 
2

嘗試ng-show而不是ng-if

<input type="text" class="col-xs-8" name="Fat" ng-show="visible" ng-click="hidden()"> 
+0

有一點[額外的信息](http://stackoverflow.com/questions/19177732/what-is-the-difference-between-ng-if-and-ng-show-ng-hide)爲什麼這應該是正確的答案。 TL; DR當你使用'ng-if'時,DOM中不再有那個元素,而'ng-show'與設置'display:none;'相同# – George

+0

@ramana我也試過ng-show。它不工作。當我點擊特定的​​時,沒有任何反應。 – shafeerambatt

+1

如果是可點擊的​​,則應將角邏輯放在​​上。 – cjs1978

相關問題