将输入值发送到打字稿(不发送按钮)

问题描述 投票:1回答:1

我有一个常规输入文本:

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

我想在用户完成输入后将用户在框中输入的内容发送到打字稿文件中(没有提交按钮等),将输入发送到打字稿。

我尝试使用此代码:Code,但不起作用。

angular
1个回答
1
投票

[Demo使用ngModel双向绑定

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

[Demo或使用ViewChild作为方法

component.ts

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

html部分

<form >
    <input #input type="text" (input)="sendInput()"/>
</form>
{{inputParam}}
© www.soinside.com 2019 - 2024. All rights reserved.