gpt4 book ai didi

html - 将输入值发送到 typescript (没有按钮发送)

转载 作者:行者123 更新时间:2023-12-03 16:54:49 24 4
gpt4 key购买 nike

我有一个常规的输入文本:

<form>
<input type="text" oninput="sendInput()" />
</form>

我想在用户完成输入后将用户在框中输入的内容发送到 typescript 文件(没有提交按钮或其他东西),将输入发送到 typescript 。

我尝试使用 this code但它不起作用。

最佳答案

Demo使用 ngModel 双向绑定(bind)

<input type="text" [(ngModel)]="inputParam"/>    
<p>{{inputParam}}</p>

Demo或使用 ViewChild 作为一种方式

组件.ts
inputParam=""
@ViewChild('input') _input: ElementRef;
sendInput(){
this.inputParam= this._input.nativeElement.value;
}

html部分
<form >
<input #input type="text" (input)="sendInput()"/>
</form>
{{inputParam}}

关于html - 将输入值发送到 typescript (没有按钮发送),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62106036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com