簡體   English   中英

無法在Angular 2中禁用選擇標簽

[英]Not able to disable the select tag in Angular 2

我有一個變量

createMode = true;

現在在輸入標簽中

<input type="text" required="required" [disabled]='createMode'>

disable正在工作,輸入已被禁用。

現在,當我使用select標簽嘗試相同操作時,它不起作用

<select required [disabled]='createMode'>
<option selected="selected" > Mango</option>
</select>

有人可以建議根據createMode的值如何禁用此選擇位置

要在createMode=true時選擇<options>元素,可以執行以下操作:

<options [attr.selected]="createMode ? true : null">

如果為null ,它將完全消失,應該消失。

您有兩種選擇:
1) 您可以使用* ngif

<select required *ngIf="!variable">
<option selected="selected" > Mango</option>
</select>

如果您的變量是用於切換選擇的變量,則輸入! 到該表達式,您將獲得與ng-hide相同的效果。
2) 您可以使用[隱藏]並將其綁定到模型

<select required [hidden]='{{BooleanVariable}}'>
<option selected="selected" > Mango</option>
</select>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM