Я хочу показать / скрыть текст пароля в моей форме входа. У меня есть код, как показано ниже.
Я пробую этот код:
<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";
}
}
}
Когда я нажимаю функцию toggleShow()
в console.log(this.show)
, показываю true false, но в шаблоне ничего не отображается. Вы можете спросить меня, пожалуйста, что не так в моем коде?
Спасибо!