angular - 隐藏密码字段内的显示眼睛图标 angular 6

标签 angular

该功能运行良好,但到目前为止我都是使用复选框来完成的 我只需要有关密码输入字段内的眼睛图标的帮助 如果可能,没有 Bootstrap 或 Font Awesome 并感谢

      myFunction() {
  let x : any = document.getElementById("inputPassword");
  if (x.type === "password") {
    x.type = "text";
  } else {
    x.type = "password";
  }
}

<input [(ngModel)]="password" type="password" id="inputPassword"  name="password"
                     placeholder="{{'Password' | translate}}"  required>
                     <input type = "checkbox" (click)="myFunction()">

最佳答案

我会按照官方记录的那样去做:

不要在组件中设置类型,而是为类型属性使用动态值。

HTML:

<input placeholder="Enter your password" [type]="hide ? 'password' : 'text'">

TS代码:

hide : boolean = true;

myFunction() {
  this.hide = !this.hide;
}

Working_Demo_with_eye_icon

关于angular - 隐藏密码字段内的显示眼睛图标 angular 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57267103/

相关文章:

angular - Protractor 与 Jasmine 不会显示堆栈跟踪以符合错误

angular - 在运行时为 AOT 编译的 Angular 应用程序获取 --locale 的值

node.js - 使用 Nodemailer 和 Webpack 时无法解析 dns 和 child_process

Angular:URL 更改不会在第一次重新加载页面

angular - 由于过度使用内存和 CPU,NgRx 和 redux 开发工具出现性能问题

angular - HTTP 请求未触发

unit-testing - 如何更改angular2单元测试中选择框的值?

angular - RxJS - Subscriber 与 Observable 和 Subscription 有何不同?

java - 将请求从服务器发送到 Web 应用程序

angular - rxjs 根据第一个答案返回不同的 Observable