<div class="form-group">
<label class="col-md-4 control-label" for="is_present">Is Present?</label>
<div class="col-md-4">
<select id="is_present" name="is_present" class="form-control" *ngIf="candidates.is_present === true">
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
</div>
我在我的html組件中有此代碼。我收到來自API的布爾數據,我想知道如果API數據爲true或false,使用*ngIf
在option
標記中添加selected
的最佳方式。Angular 2 ng如果選擇框
你將從'selected'變量中從服務器檢索什麼值? –
我收到一個布爾值。我更新了問題 –
然後只是'[(ngModel)] =「candidates.is_present」'給你的選擇,就是這樣:) Sajeeth已經給出了答案。 –