[英]Enable button based on input - Angular/Typescript
My button has to enable when I fill my input.当我填写我的输入时,我的按钮必须启用。 Currently it keeps being disabled.
目前它一直被禁用。
HTML button: HTML 按钮:
<button pButton type="button" class="buttonCSS" [disabled]="buttonDisabled" label="Boeken" id="button" (click)="on_Boek()"></button>
HTML input HTML 输入
<input type="text" [(ngModel)]="sBoekOmschrijving" (onchange)="on_ChangeInput()" pInputText/>
TypeScript function打字稿功能
on_ChangeInput()
{
this.buttonDisabled = false
}
Typescript button disabled always true禁用打字稿按钮始终为真
buttonDisabled = true
Most likely a stupid question.. but I really can't figure it out.. thanks anyway.很可能是一个愚蠢的问题......但我真的无法弄清楚......无论如何谢谢。 I am not allowed to use Jquery.
我不允许使用 Jquery。
onchange
are for selects, not inputs onchange
用于选择,而不是输入(onchange)
doesn't exist in Angular (it's change
) (onchange)
在 Angular 中不存在(它是change
)(input)
could do the trick (input)
可以解决问题But the best solution would be :但最好的解决方案是:
<button pButton type="button" class="buttonCSS" [disabled]="!sBoekOmschrijving" label="Boeken" id="button" (click)="on_Boek()"></button>
<input type="text" [(ngModel)]="sBoekOmschrijving" pInputText/>
By relying on falsy values, you put the condition通过依赖虚假值,你把条件
Disable the button if the
sBoekOmschrijving
field has no value如果
sBoekOmschrijving
字段没有值,则禁用该按钮
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.