Angular响应式表单-2个密码类型输入框-第二个不响应隐藏/显示按钮的点击
创始人
2024-10-30 05:30:42
0

在模板中我们需要添加隐藏/显示按钮并对其进行操作。解决方法如下所示:

1.模板:

2.组件:

import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({ selector: 'app-password', templateUrl: './password.component.html', styleUrls: ['./password.component.css'] }) export class PasswordComponent { hidePassword = true; // initial value for hidePassword

form = new FormGroup({ password1: new FormControl('', [Validators.required, Validators.minLength(6)]), password2: new FormControl('', [Validators.required, Validators.minLength(6)]) });

hideUnhide() { this.hidePassword = !this.hidePassword; // toggle hidePassword }

get password2Type() { return this.hidePassword ? 'password' : 'text'; // determine input type based on hidePassword } }

  1. 模板中使用:

这里使用了一个新的getter方法 password2Type 来根据 hidePassword的状态(true或false)来切换第二个密码框的input类型。

在按钮的点击事件方法中,使用 ! 操作符将 hidePassword 改为相反的值, 这样就可以动态地切换输入密码时的显示和隐藏了。

相关内容

热门资讯

外挂演示!智星德州插件2024... 外挂演示!智星德州插件2024最新版,哈糖大菠萝辅助器-本来真的有辅助脚本(哔哩哔哩)智星德州插件2...
外挂办法!pokernow辅助... 外挂办法!pokernow辅助工具,poker master辅助-原来一直都是有辅助攻略(哔哩哔哩)...
外挂方案!智星菠萝德州插件怎么... 外挂方案!智星菠萝德州插件怎么下载,智星德州辅助译码插件靠谱吗-一直有辅助方法(哔哩哔哩)1、下载好...
外挂窍门!哈糖大菠萝怎么开挂,... 外挂窍门!哈糖大菠萝怎么开挂,德普之星透视辅助软件-原来是真的有辅助app(哔哩哔哩)小薇(辅助器软...
外挂法子!德州局透视脚本,来玩... 外挂法子!德州局透视脚本,来玩app破解版-果然是真的有辅助软件(哔哩哔哩)1.德州局透视脚本 选牌...
外挂诀窍!约局吧德州真的有透视... 外挂诀窍!约局吧德州真的有透视挂吗,xpoker辅助助手-本来真的有辅助技巧(哔哩哔哩)1、全新机制...
外挂操作!竞技联盟破解版最新版... 外挂操作!竞技联盟破解版最新版,uupoker透视-竟然一直总是有辅助脚本(哔哩哔哩)竞技联盟破解版...
外挂练习!werplan外开挂... 外挂练习!werplan外开挂,德普之星透视免费-竟然有辅助神器(哔哩哔哩)1、每一步都需要思考,不...
外挂演示!fishpoker透... 外挂演示!fishpoker透视,智星德州插件2024最新版-真是真的是有辅助教程(哔哩哔哩)1、智...
外挂绝活!sohoo poke... 外挂绝活!sohoo poker辅助,红龙poker辅助-其实有辅助工具(哔哩哔哩)1、下载好soh...