2017-03-13 5 views
1

Ich möchte mehrere Radio-Optionen auswählen.Neu zu angularjs.Wählen Sie mehrere Radio-Optionen in angularjs Ausgabe

Schritte, das Problem zu produzieren:

  1. Wählen Sie ein beliebiges Land aus der ersten Auswahlmenü -> Grund wählen
  2. aus der 2. Auswahlmenü jedes Land auswählen -> Wählen Sie Reason C

Hier verschwindet der obige Grund Eine Option und nur Grund C ist ausgewählt. Ich möchte die zwei verschiedenen Gründe für verschiedene Länder Abschnitt halten.

hier ist die Geige http://jsfiddle.net/Lini7/knfsv64m/8/

var app = angular.module('myApp', []); 
app.controller('myController', function ($scope) { 
$scope.showReasonA = function showReasonA(checkNoTin) { 
    console.log("print the notin value from data",this.item.noTin); 
    if (!this.item.country) return false; 
    var selectedCountry = this.item.country.country.toLowerCase(); 
    var fourCountries = ["cayman islands", "albania"] 
    var isIt = fourCountries.indexOf(selectedCountry) >= 0; 
    console.log("print match country val",isIt); 
    console.log("get checknotin value before assign",checkNoTin); 
    if (checkNoTin) this.item.noTin = true; 
    console.log("final checknotin val",checkNoTin); 
    return isIt; 
    } 
}); 

und die Aussicht

<body> 
<div ng-app="myApp"> 
    <div ng-controller="myController"> 
<select name="country_0" ng-model="item.country" ng-options="" required="required" class="ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" style=""><option value="" selected="selected"></option><option label="AFGHANISTAN" value="object:835">AFGHANISTAN</option><option label="cayman islands" value="object:836">cayman islands</option><option label="ALBANIA" value="object:837">ALBANIA</option><option label="ALGERIA" value="object:838">ALGERIA</option><option label="AMERICAN SAMOA" value="object:839">AMERICAN SAMOA</option></select> 
<div class="row"> 
    <label class="checkbox"> 
    <input type="checkbox" ng-model="item.noTin" ng-disabled="item.tin" ng-checked="showReasonA(true)" ng-required="item.noTin" name="checkboxNoTin"/> 
    </label><span translate="transactions.changeAddress.crs.yes.me_no_tin" style="margin-top: 10px" class="col-value"></span> 
</div> 
<div ng-if="item.noTin" class="row"> 
    <div class="col padding-top-xs"><span translate="transactions.changeAddress.crs.select_reason" style="margin-bottom: 12px;" class="pol-value col-value"></span> 
    <div ng-if="item.country.tin == true" ng-init="item.reason = 0" class="row margin-bottom-medium"> 
     <label class="radio-button"> 
     <input type="radio" name="reason" ng-model="item.reason" ng-value="A" required="required"/><span class="indicator"></span><span translate="transactions.changeAddress.crs.yes.reason1"></span> 
     </label> 
    </div> 
    <div ng-if="!showReasonA()" class="row margin-bottom-medium"> 
     <div class="col"> 
     <label class="radio-button"> 
      <input type="radio" name="reason" ng-model="item.reason" ng-value="B" required="required"/><span class="indicator"></span><span translate="transactions.changeAddress.crs.yes.reason2_title"></span> 
      <label class="item item-input input-margin"> 
      <textarea ng-model="item.othersReason" ng-required="item.reason == 2" rows="5"></textarea> 
      </label> 
     </label> 
     </div> 
    </div> 
    <div ng-if="!showReasonA()" class="row margin-bottom-medium"> 
     <div class="col"> 
     <label class="radio-button"> 
      <input type="radio" name="reason" ng-model="item.reason" ng-value="C" required="required"/><span class="indicator"></span><span translate="transactions.changeAddress.crs.yes.reason3"></span> 
     </label> 
     </div> 
    </div> 
    </div> 
</div> 
<select name="country_0" ng-model="item.country" ng-options="" required="required" class="ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" style=""><option value="" selected="selected"></option><option label="AFGHANISTAN" value="object:835">AFGHANISTAN</option><option label="cayman islands" value="object:836">cayman islands</option><option label="ALBANIA" value="object:837">ALBANIA</option><option label="ALGERIA" value="object:838">ALGERIA</option><option label="AMERICAN SAMOA" value="object:839">AMERICAN SAMOA</option></select> 
<div class="row"> 
    <label class="checkbox"> 
    <input type="checkbox" ng-model="item.noTin" ng-disabled="item.tin" ng-checked="showReasonA(true)" ng-required="item.noTin" name="checkboxNoTin"/> 
    </label><span translate="transactions.changeAddress.crs.yes.me_no_tin" style="margin-top: 10px" class="col-value"></span> 
</div> 
<div ng-if="item.noTin" class="row"> 
    <div class="col padding-top-xs"><span translate="transactions.changeAddress.crs.select_reason" style="margin-bottom: 12px;" class="pol-value col-value"></span> 
    <div ng-if="item.country.tin == true" ng-init="item.reason = 0" class="row margin-bottom-medium"> 
     <label class="radio-button"> 
     <input type="radio" name="reason" ng-model="item.reason" ng-value="A" required="required"/><span class="indicator"></span><span translate="transactions.changeAddress.crs.yes.reason1"></span> 
     </label> 
    </div> 
    <div ng-if="!showReasonA()" class="row margin-bottom-medium"> 
     <div class="col"> 
     <label class="radio-button"> 
      <input type="radio" name="reason" ng-model="item.reason" ng-value="B" required="required"/><span class="indicator"></span><span translate="transactions.changeAddress.crs.yes.reason2_title"></span> 
      <label class="item item-input input-margin"> 
      <textarea ng-model="item.othersReason" ng-required="item.reason == 2" rows="5"></textarea> 
      </label> 
     </label> 
     </div> 
    </div> 
    <div ng-if="!showReasonA()" class="row margin-bottom-medium"> 
     <div class="col"> 
     <label class="radio-button"> 
      <input type="radio" name="reason" ng-model="item.reason" ng-value="C" required="required"/><span class="indicator"></span><span translate="transactions.changeAddress.crs.yes.reason3"></span> 
     </label> 
     </div> 
    </div> 
    </div> 
</div> 
</div> 
</div> 
</body> 
+0

hier ist die Geige http://jsfiddle.net/Lini7/knfsv64m/8/ – Lini

+0

Sie mehrere Radio-Optionen oder eingestellt auswählen möchten Standard-Kontrollkästchen und Radio-Button beim Laden der Seite? Könnten Sie das Problem näher erläutern? –

+0

@SaravananSachi hat meine Kommentare hinzugefügt. Bitte überprüfen – Lini

Antwort

1

eine Eingabe zu machen, wie versteckt sie initialisiert werden können sollte

<p ng-show="condition">I'm shown</p> 

und dieser Zustand Wert im Rahmen Ihres Controllers

um eine Show-Eingabe auszublenden, können Sie ng-if verwenden. Es ist besser, ng-if für dynamische Eingaben zu verwenden. siehe Details here

Jetzt für Ihren Fall können Sie item.reason im Zustand verwenden, um Ihre Eingabe ein- und auszublenden.

<input type="radio" name="reason" ng-model="item.other" ng-value="C" required="required" ng-if="item.reason='object:836'" /> 
+0

@Lini siehe meine Antwort das könnte Ihnen helfen –

+0

mein Problem ist nur ein Radio-Button ausgewählt ist. In der zweiten Länderliste habe ich die gleichen Grundoptionen zu wählen, aber wenn ich irgendeine Option auswähle verschwindet die erste Länderoption. Ich möchte die zwei Gründe für verschiedene Länder halten. – Lini

+0

sollten Sie das Modell umbenennen, dann geben das gleiche Modell wird nicht funktionieren –

0

bekam schließlich die Lösung

ich das Optionsfeld Name mit Index gerade hinzugefügt haben dann es funktionierte, die für jede Gruppe von Tasten verschiedene Namen geben.

name = 'Grund _ {{$ Index}}'