Javascript Ionic 2在文本框中插入10位数字时调用函数

Javascript Ionic 2在文本框中插入10位数字时调用函数,javascript,angular,ionic2,Javascript,Angular,Ionic2,我是离子2/角2的新手。 我想在用户完成10位手机号码输入时显示一个运营商选择框。 到目前为止,我已经在ts中创建了一个函数 showOperators() { let len = this.mobileNo.length; if(len==10) { this.isOperator = True; } else { this.isOperator = False; } } 并将此函数称为 <ion

我是离子2/角2的新手。
我想在用户完成10位手机号码输入时显示一个运营商选择框。 到目前为止,我已经在ts中创建了一个函数

showOperators()
{
    let len = this.mobileNo.length;
    if(len==10)
    {
        this.isOperator = True;
    }
    else
    {
        this.isOperator = False;
    }
} 
并将此函数称为

<ion-input (keypress)="showOperators()" [(ngModel)]="mobileNo"></ion-input>  

要显示的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>  

操作员1
操作员2

它显示了所需的功能。但我想知道的是,我使用的是正确的方法,还是有其他好的解决方案

这样做可以避免任何代码落后:

  <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>

操作员1
操作员2
假设更少的代码意味着简单,这可能会更好