TextField focus()不起作用

时间:2016-10-20 08:35:56

标签: nativescript angular2-nativescript

使用sample-Groceries-angular 我点击按钮

尝试关注密码而不是电子邮件
┌──────────────────┬─────────────────┬────────────────┬───────────────┐
│ Component        │ Current version │ Latest version │ Information   │
│ nativescript     │ 2.3.0           │ 2.3.0          │ Up to date    │
│ tns-core-modules │ 2.3.0           │ 2.3.0          │ Up to date    │
│ tns-android      │ 2.3.0           │ 2.3.0          │ Up to date    │
│ tns-ios          │                 │ 2.3.0          │ Not installed │
└──────────────────┴─────────────────┴────────────────┴───────────────┘

的xml:

<TextField #email hint="Email Address" keyboardType="email" [(ngModel)]="user.email"
autocorrect="false" autocapitalizationType="none"></TextField>
<TextField #password hint="Password" secure="true" [(ngModel)]="user.password"></TextField>
<Button text="Focus Password" (tap)="focusDat()"></Button>

打字稿:

@ViewChild("password") password: ElementRef;
focusDat() {
  let password = <TextField>this.name.nativeElement;
  console.log(password.focus());
}

输出:

JS: false

1 个答案:

答案 0 :(得分:1)

感谢Nikolay Tsonev,我只关注错误的领域 是:

let password = <TextField>this.name.nativeElement;

应该是:

let password = <TextField>this.password.nativeElement;

它工作正常,只是犯了一个愚蠢的错误......