我有用户名和密码字段。我想为用户提供显示/隐藏密码文本选项。我在this plunker.中创建了代码

<ion-content class="has-header" padding>
 <form>
    <ion-item>
      <ion-label floating>Username</ion-label>
      <ion-input type="text">  </ion-input>
    </ion-item>


    <ion-item *ngIf="passTextHide">
      <ion-label floating>Password</ion-label>
      <ion-input type="password" class="showhideinput">  </ion-input>
      <span (click)="toggleShow($event)" item-right>Show</span>
    </ion-item>

    <ion-item *ngIf="passTextShow">
      <ion-label floating>Password</ion-label>
      <ion-input type="text" class="showhideinput">  </ion-input>
     <span (click)="toggleShow($event)" item-right>Hide</span>
    </ion-item>

    <ion-row>
      <ion-col>
        <button type="submit" primary block>submit</button>
      </ion-col>
    </ion-row>
  </form>
</ion-content>

单击事件正在发生,但我无法在密码字段中看到任何文本更改。

最佳答案

你可以这样做:
HTML格式:

<ion-input type={{type}} class="showhideinput">{{hideorshow}} </ion-input>

  <button (click)="toggleShow($event)" item-right>{{hideorshow}}</button>

代码:
  hideorshow="SHOW"
    type="password";


    toggleShow(){
       var state=  this.type

    if(state==="password"){

      this.type='text';
      this.hideorshow="HIDE";

    }
    else{

      this.type="password"
      this.hideorshow="SHOW"
    }
   }

07-24 09:46
查看更多