答案 0 :(得分:2)
尝试使用双向数据绑定,如[(ngModel)]
<select class="form-control" [(ngModel)]="SelectedCarType" >
<option *ngFor="let c of CarTypes" [value]="c.CarTypeId">
{{c.CarDescription}}</option>
</select>
<div *ngIf="SelectedCarType === 1" class="form-group" style="width:50%">
<label class="label label-info" for="Mileage">Mileage:</label>
<input class="form-control" type="text" name="Mileage" id="Mileage"/>
</div>
<div class="form-group" style="width:50%">
<label class="label label-info" for="Kilometres">Kilometres:</label>
<input class="form-control" type="text" name="Kilometres"
id="Kilometres" />
</div>
答案 1 :(得分:1)
<select class="form-control" [ngModel]="SelectedCarType"
name="SelectedCarType" id="SelectedCarType">
<option *ngFor="let c of CarTypes" [value]="c.CarTypeId">
{{c.CarDescription}}</option>
</select>
<div *ngIf="SelectedCarType ===1" class="form-group" style="width:50%">
<label class="label label-info" for="Mileage">Mileage:</label>
<input class="form-control" type="text" name="Mileage" id="Mileage"/>
</div>
<div *ngIf="SelectedCarType != 1" class="form-group" style="width:50%">
<label class="label label-info" for="Kilometres">Kilometres:</label>
<input class="form-control" type="text" name="Kilometres"
id="Kilometres" />
</div>