使用typescript

时间:2018-06-04 11:13:03

标签: angular

TS

objage: number;
underFlag: boolean = false
aboveFlag: boolean = false
ageValidation: any;
num: any;

ageUpdation(PATIENT_AGE) 
{
    alert(JSON.stringify(PATIENT_AGE))
    if (PATIENT_AGE > 18) 
    {
        this.underFlag = false;
        this.aboveFlag = true;
        alert("hi");
    }
    else 
    {
        this.underFlag = true;
        this.aboveFlag = false;
        alert("hi2");
    }
}

HTML

<td colspan="2">
    <input type="number" formControlName="PATIENT_AGE"  placeholder="Enter Age b/w 1 and 100" class="form-control input-sm"  min="1" max="100" [(ngModel)]="PATIENT_AGE" name="PATIENT_AGE" (change)="ageUpdation(PATIENT_AGE)" required/>
    <div id="forAgeDiv"><span id="forAge"></span></div>
</td>

<td>
    <input type="radio" name="PATIENT_TYPE"  formControlName="PATIENT_TYPE"  value="Pediatric" [disabled]="aboveFlag">Pediatric 
</td>

<td>
    <input type="radio" name="PATIENT_TYPE"  formControlName="PATIENT_TYPE"  value="Adolescent" [disabled]="underFlag"> Adolescent
    <br>
</td>

如何根据文本框值启用和禁用单选按钮。 如果我进入年龄超过18岁,青少年单选按钮就会启用。

否则我进入年龄低于18岁儿科单选按钮将启用。

2 个答案:

答案 0 :(得分:1)

它对我有用:

          Yield (in kg)-0  Yield (in kg)-1  Yield (in kg)-2  Yield (in kg)-3   /
Village1   0.22             0.23             0.55             0.20   
Village2   0.88             0.89             0.63             0.55   

                         Average  
Village1                 0.3000  
Village2                 0.7375

答案 1 :(得分:0)

试试这个...我不明白你为什么要使用&#39; formControlName&#39;属性。这对我有用

objage: number;
underFlag: boolean = false
aboveFlag: boolean = false
ageVaildation: any;
num: any;
patient_age: any;

geUpdation(patient_age) {
 alert(JSON.stringify(patient_age))
 if (patient_age > 18) {
    this.underFlag = false;
    this.aboveFlag = true;
    alert("hi");
 }else {
    this.underFlag = true;
    this.aboveFlag = false;
    alert("hi2");
 }
}

<td colspan="2">
 <input type="number" placeholder="Enter Age b/w 1 and 100" class="form-control input-sm"  min="1" max="100" [(ngModel)]="patient_age" name="patient_age" (change)="ageUpdation(patient_age)" required/>
 <div id="forAgeDiv"><span id="forAge"></span></div>
</td>
<td>
 <input type="radio" name="patient_type"   value="Pediatric" [disabled]="aboveFlag">Pediatric 
</td>
<td>
 <input type="radio" name="patient_type"  value="Adolescent" [disabled]="underFlag"> Adolescent
</td>