Angular 如何将输入值传递到html中的事件调用中?
我需要将输入的值传递给一个变量,然后我可以使用该变量单击按钮 我的htmlAngular 如何将输入值传递到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
<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)”>