[英]Ionic 2 call a function when exactly 10 digits inserted in textbox
I am new to ionic 2 / angular 2. 我是离子2 /角2的新手。
I want to display a operators select box exactly when the user complete the 10 digit mobile number input. 我想在用户完成10位手机号码输入时准确显示一个操作员选择框。 Till now i have created a function in ts
到目前为止,我已经在ts中创建了一个函数
showOperators()
{
let len = this.mobileNo.length;
if(len==10)
{
this.isOperator = True;
}
else
{
this.isOperator = False;
}
}
and calling this function as 并调用此函数为
<ion-input (keypress)="showOperators()" [(ngModel)]="mobileNo"></ion-input>
and the div to display is 而要显示的div是
<div *ngIf="isOperator">
<ion-select [(ngModel)]="operators">
<ion-option value="1">Operator1</ion-option>
<ion-option value="2">Operator2</ion-option>
</ion-select>
</div>
it shows the desired functionality. 它显示了所需的功能。 But i want to know is i am using the right way or is there any other good solution for this.
但是我想知道是我使用的是正确的方法,还是有其他好的解决方案。
You can avoid having any code-behind by doing this: 您可以通过执行以下操作避免任何代码隐藏:
<ion-input [(ngModel)]="mobileNo"></ion-input>
<div *ngIf="mobileNo?.length == 10">
<ion-select>
<ion-option value="1">Operator1</ion-option>
<ion-option value="2">Operator2</ion-option>
</ion-select>
Assuming less code means simplicity, this might be better. 假设更少的代码意味着简单,那可能会更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.