show/hide password text using angular2

后端 未结 8 1337
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 11:53

i want to show/hide the password text based on the user click. But i am getting the following error saying:

export class App {
    password = \"secret\"         


        
8条回答
  •  终归单人心
    2021-02-15 12:15

    You could do something like this:

    In your App class.

       _show = false
       _pwdType = 'pwd'
    
       toggleShow() {
    
          this._show = !this._show
          this._pwdType = this._show ? 'text' : 'password'
    
       }//toggleShow
    

    In your html

     
    

    Having said that I like @codtex's answer better

提交回复
热议问题