我有一个带单选按钮的表单,如果用户选择否,则默认值s' 0'应该添加到输入标记,我尝试使用value='0'
加载表单时将0设置为默认值,但在加载表单时不会反映此值。
<form #form="ngForm" (ngSubmit)="modifyMilkForm(form)" novalidate>
<ion-row>
<ion-col style="text-align: right;">
<ion-label><b>Today Received :</b></ion-label>
</ion-col>
<ion-col>
<ion-list radio-group name="checkBox" [(ngModel)]="autoManufacturers">
<ion-item>
<ion-label>Yes</ion-label>
<ion-radio [value]="true"></ion-radio>
</ion-item>
<ion-item>
<ion-label>No</ion-label>
<ion-radio [value]="false"></ion-radio>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
<ion-row>
<ion-col style="text-align: right;" >
<ion-label><b>Price :</b></ion-label>
</ion-col>
<ion-col>
<ion-item name="price" [(ngModel)]="enteredPrice" required>
<ion-input type="number" value="0" placeholder="Number"></ion-input>
</ion-item>
</ion-col>
</ion-row>
<button small [disabled]=!form.valid style="text-transform: none" ion-button type="submit" value="Submit" small>Submit</button>
</form>
有人可以帮我修复这个
答案 0 :(得分:1)
这是
class initRadioGroup {
selectedRadio = {"value":"N"};
}
<md-radio-group class="form-control" [(ngModel)]="selectedRadio.value"
id="radioList" formControlName="selectedRadio">
<md-radio-button [value]="'N'">N</md-radio-button>
<md-radio-button [value]="'M'">M</md-radio-button>
</md-radio-group>