首页 > 解决方案 > 如何启用禁用的文本框 onclick 使用角度的按钮

问题描述

我有一个使用简单的禁用 html 标记禁用的文本框。单击启用按钮时需要启用它,单击禁用按钮时需要再次禁用它。这是下面的代码 -

app.component.html

<input  type="text" disabled value="Sample text box">

<button (click)="enable()" type="button">Enable</button>
<button (click)="disable()" type="button">Disable</button>

app.component.ts

enable(){

}

disable(){

}

标签: htmlangular

解决方案


您可能不需要 TypeScript,您可以从模板中引用输入

<input #input type="text" disabled value="Sample text box">

<button (click)="input.disabled = false" type="button">Enable</button>
<button (click)="input.disabled = true" type="button">Disable</button>

推荐阅读