Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何将输入值传递到html中的事件调用中?_Angular - Fatal编程技术网

Angular 如何将输入值传递到html中的事件调用中?

Angular 如何将输入值传递到html中的事件调用中?,angular,Angular,我需要将输入的值传递给一个变量,然后我可以使用该变量单击按钮 我的html <p class="mgRight">Second: <input type="number" min="1" value="10"/></p> <button class="mgRight" type="button" (click)="callOnce(x)">Active Once After...</button> 您需要将输入绑定到typescrip

我需要将输入的值传递给一个变量,然后我可以使用该变量单击按钮

我的html

<p class="mgRight">Second: <input type="number" min="1" value="10"/></p>
<button class="mgRight" type="button" (click)="callOnce(x)">Active Once After...</button>

您需要将输入绑定到typescript中的某些属性

html

这只是一种方法。您还应该查看HttpClient以发出xhr请求

编辑:
如果您绑定到一个数字输入,myProperty或您称之为的任何东西也可以是一个数字。归根结底,这是一个纯数字,因为javascript不关心typescript中的类型。

如果不想存储值,甚至可以执行以下操作

<input #yourInput type=“text”>

<button (click)=“callOnce(yourInput.value)”>
在模板中创建变量并访问其值

<input type="number" min="1" value="10" [(ngModel)]="myProperty" />
myProperty: number;

callOnce() {
  var url = "api/url/" + this.myProperty;
  var xmlHttp = new XMLHttpRequest();    
  xmlHttp.open("GET", url, false);
  xmlHttp.send(null);
  return xmlHttp.responseText;
}
<input #yourInput type=“text”>

<button (click)=“callOnce(yourInput.value)”>