如何在ionic2中执行只读或禁用?

时间:2016-12-20 06:42:27

标签: angular ionic2

实际上我试图将一个字段设置为只读或禁用离子2形式:

<ion-item>
    <ion-label fixed>Category <ion-icon name="ios-arrow-forward"></ion-icon></ion-label>
    <ion-input type="text" [disabled]="false" id="category_name" class="form-control" formControlName="category_name" (click)="category()" [(ngModel)]="category_name"></ion-input>
</ion-item>

我也使用[readonly] =“false”。

我知道这是一个问题,git也存在问题:

https://github.com/driftyco/ionic/issues/6408 ..

所以任何帮助我如何解决它。

2 个答案:

答案 0 :(得分:6)

我用它来解决Ionic 2:

  In .ts file:
  ------------
  isReadonly() {
    return this.isReadonly;   //return true/false 
  }


  In .html file:
  --------------
  <ion-input type="text"  [readonly]="isReadonly()"></ion-input>

答案 1 :(得分:0)

我使用了以下代码并且工作正常。

<ion-input type="text" [readonly]="!userSessionStarted" value="" [(ngModel)]="userQuery" (change)="sendQueryToServer()"></ion-input>

变量通过ui逻辑在true / false之间切换,不一定只能使用函数。