简体   繁体   English

select 选项更改不保存无线电输入中的值

[英]select option change don't save the value in radio input

I have a list of elements that, selected via a radio input, must output the [value] .我有一个元素列表,通过radio输入选择,必须 output [value] The problem is that the select of choice of the value does not find me the secondary value when I go to change the select (always remains the value of prezzoRiepilogo instead of prezzoRiepilogoTwo , when i change). The problem is that the select of choice of the value does not find me the secondary value when I go to change the select (always remains the value of prezzoRiepilogo instead of prezzoRiepilogoTwo , when i change). Why?为什么? How can I fix it?我该如何解决?

<ul class="list-group">
               <li class="list-group-item" *ngFor="let interventoStrutturale of interventi">
                   <td style="float: left;">{{interventoStrutturale.intervento.codice}} {{interventoStrutturale.variante}} - {{interventoStrutturale.intervento.descrizione}}<br>

                       <select [(ngModel)]="interventoStrutturale.tipo_sup">
                           <option disabled value="1">Selection one</option>
                           <option value="2">Selection two</option>
                           <option value="3">Selection three</option>
                       </select>
</td>

                   <td style="float: right;" [ngSwitch]="interventoStrutturale.tipo_sup">

                       <label class="form-check-inline" *ngSwitchCase="interventoStrutturale.tipo_sup == 2">
                       <input class="form-check-input" type="radio" name="radio"
                           [value]="interventoStrutturale.prezzoRiepilogo" (change)="onChangeIntervento($event.target.value)">
                     </label>

<label class="form-check-inline" *ngSwitchCase="interventoStrutturale.tipo_sup == 3">
                       <input class="form-check-input" type="radio" name="radio"
                           [value]="interventoStrutturale.prezzoRiepilogoTwo" (change)="onChangeIntervento($event.target.value)">
                     </label>

                     <label class="form-check-inline" *ngSwitchDefault>
                       <input class="form-check-input" type="radio" name="radio"
                           [value]="interventoStrutturale.prezzoRiepilogo" (change)="onChangeIntervento($event.target.value)">
                     </label>
                   </td>
               </li>
           </ul>  
           

onChangeIntervento(intervento: number) {
   this.prezzoStrutturale = intervento
   this.elementoSelezionato = []
   this.interventi.forEach(c => {
     if(this.prezzoStrutturale == c.prezzoRiepilogo) {
       this.elementoSelezionato.push(c)
     } 
     if(this.prezzoStrutturale == c.prezzoRiepilogoTwo) {
       this.elementoSelezionato.push(c)
     }
   })
}

I think you do not apply SwitchCase correctly.我认为您没有正确应用 SwitchCase。 Try it this way:试试这种方式:

<td style="float: right;" [ngSwitch]="interventoStrutturale.tipo_sup">

    <label class="form-check-inline" *ngSwitchCase="2">
        <input class="form-check-input" type="radio" name="radio"
                       [value]="interventoStrutturale.prezzoRiepilogo" (change)="onChangeIntervento($event.target.value)">
    </label>

    <label class="form-check-inline" *ngSwitchCase="3">
        <input class="form-check-input" type="radio" name="radio"
                       [value]="interventoStrutturale.prezzoRiepilogoTwo" (change)="onChangeIntervento($event.target.value)">
    </label>

    <label class="form-check-inline" *ngSwitchDefault>
        <input class="form-check-input" type="radio" name="radio"
                       [value]="interventoStrutturale.prezzoRiepilogo" (change)="onChangeIntervento($event.target.value)">
    </label>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM