2013-11-21 42 views
1

我有一個電臺:用隱藏和收音機隱藏元素?

<div class="row"> 
    <div class="col15"> 
    <input type="radio" id="client_yes" name="client" ng-model="entry.client" ng-required="true" value="yes"><label for="client_yes">Yes</label> 
    </div> 
    <div class="col15"> 
    <input type="radio" id="client_no" name="client" ng-model="entry.client" ng-required="true" value="no"><label for="client_no">No</label> 
    </div> 

</div> 

當client_yes選擇我要在表格上的一些問題,以使用NG隱藏隱藏。

我已經在文檔中檢查出的例子:

http://docs.angularjs.org/api/ng.directive:ngHide

這將使用複選框來隱藏:

ng-hide="checked" 

經過是對的NG-模型的名稱複選框,我只是不確定如何使用收音機工作,因爲它們都有相同的型號名稱?

回答

1

在問題div上使用ng-hide指令,如下所示:

ng-hide="entry.client=='yes'" 

見plunker:http://plnkr.co/edit/o2dXzq3lTGy4iBPxS6MT?p=preview

這是HTML代碼:

<body ng-app="app" ng-controller="Controller"> 
    <div class="row"> 
     <div class="col15"> 
     <input type="radio" id="client_yes" name="client" ng-model="entry.client" ng-required="true" value="yes" /> 
     <label for="client_yes">Yes</label> 
     </div> 
     <div class="col15"> 
     <input type="radio" id="client_no" name="client" ng-model="entry.client" ng-required="true" value="no" /> 
     <label for="client_no">No</label> 
     </div> 

     <div class="col15" ng-hide="entry.client=='yes'"> 
     question to hide 
     </div> 
     <div class="col15"> 
     question NOT to hide 
     </div> 
     <div class="col15" ng-hide="entry.client=='yes'"> 
     question to hide 
     </div> 
    </div> 
    </body> 
+0

感謝。有沒有辦法隱藏問題開始,因爲在開始時,沒有單選按鈕被選中。 – panthro

+0

一個簡單的方法是用ng-show替換ng-hide,例如:'ng-show =「entry.client =='no'」' –

0

According to the docs,你可以使用value屬性每個單選按鈕設置爲不同的值上的選擇:

<div class="row"> 
    <div class="col15"> 
    <input type="radio" id="client_yes" name="client" value="yes" ng-model="entry.client" ng-required="true"><label for="client_yes">Yes</label> 
    </div> 
    <div class="col15"> 
    <input type="radio" id="client_no" name="client" value="no" ng-model="entry.client" ng-required="true"><label for="client_no">No</label> 
    </div> 

然後,你可以隱藏基於價值:

ng-hide="entry.client == 'yes'"