【发布时间】:2018-08-17 14:44:37
【问题描述】:
我想在我的登录表单中显示/隐藏密码文本。我有如下代码。
我试试这个代码:
<GridLayout margin="10" verticalAlignment="center" backgroundColor="#ffffff">
<StackLayout margin="10" verticalAlignment="center" [formGroup]="signUpForm" padding="15">
<StackLayout class="input-field">
<TextField formControlName="username" hint="Username"></TextField>
</StackLayout>
<StackLayout class="input-field">
<TextField formControlName="password" hint="Password" secure="true">
</TextField>
</StackLayout>
<Label text ="show/hide" (tap)="toggleShow()"></Label>
</StackLayout>
</GridLayout>
在component.ts中我写了这段代码:
export class LoginComponent implements OnInit {
signUpForm: FormGroup;
show = false;
type= 'password';
constructor(....) {
this.signUpForm = this.formBuilder.group({
username: ["", Validators.required],
password: ["", Validators.required]
});
}
toggleShow()
{
this.show = !this.show;
if (this.show){
this.type = "text";
}
else {
this.type = "password";
}
}
}
当我在console.log(this.show) 中单击函数toggleShow() 时显示真假,但在模板中不显示任何内容。你能问我任何想法吗,我的代码有什么问题?
谢谢!
【问题讨论】:
标签: angular typescript nativescript show-hide angular2-nativescript