Angular 2 - 如何禁用按钮并将其启用,直到在下拉列表中选择某个值为止?

时间:2017-01-06 17:17:51

标签: angular

12&e

其中

 <select id="dpname" [(ngModel)]="nameSelectedVal">
        <option value="0">Select one...</option>
        <option *ngFor="let name of names" value = {{name.code}}> 
             {{name.definition}} 
        </option>
 </select>

<button class="btnView">VIEW</button>

所以,默认情况下我将nameSelectedVal值设置为&#34; -1&#34;显示&#34;选择一个......&#34;那就是我想要禁用按钮,直到用户选择除了&#34之外的其他一些值;选择一个...&#34;然后在选择与&#34不同的其他值时启用它;选择一个...&#34;。

我在类文件中设置names = [ { "code": -1, "definition": "Select one..." }, { "code": 1, "definition": "Affiliates" }, { "code": 2, "definition": "Asia/Pacific" }, { "code": 3, "definition": "EMEA" }, { "code": 4, "definition": "North America" }, { "code": 5, "definition": "Latin America" }, { "code": 6, "definition": "Web" } ] ;

谢谢!

1 个答案:

答案 0 :(得分:4)

我只想为按钮添加[disabled]="nameSelectedVal === '-1'"