我已经获取了数字类型的 ionic 输入值,并且想要访问我的 ngAfterViewInit 下的值,我得到了未定义的值,请让我知道正确的解决方案吗?
下面是代码:
<ion-input id="qty" type="number" placeholder="Enter Stop Index" (ngModel)="stop"></ion-input>
代码:
ngAfterViewInit() {
var slidetostop= (<HTMLInputElement>document.getElementById('qty')).value;
}
最佳答案
你可以用javascript来实现它。看看下面的代码。
var slidetostop ="8" //you can put any static number.
document.getElementById("qty").addEventListener("keyup", function () {
slidetostop = parseInt((<HTMLInputElement>document.getElementById("qty")).value);
}, false);
关于javascript - 如何在 Ionic2 中的 ngAfterViewInit() 下访问 ionic 输入数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43718458/