简体   繁体   English

ionic动态绑定最大长度

[英]ionic Bind maxlength dynamically ionic2

My requirement is to bind maxlength to ion-input . 我的要求是将maxlength绑定到ion-input I have tried using interpolation concept to bind. 我尝试使用插值概念进行绑定。

My html 我的HTML

 <ion-list >
    <ion-item *ngFor=" let a of arr_label">
      <ion-label floating>{{a.lblname}}</ion-label>
      <ion-input maxlength={{a.maxlent}}   [(ngModel)]="a.Val" type="text"></ion-input>
</ion-item>

.ts .ts

arr_label:any[]=[];
this.arr_label.push({maxlent:10});

Is there something am missing... any help is quite appreciable. 是否缺少任何东西……任何帮助都是相当可观的。

You can bind to attributes in 3 different ways 您可以通过3种不同的方式绑定到属性

Bind directly to it, if it's a native attribute: 如果是本机属性,则直接与其绑定:

<ion-input [maxlength]="a.maxlent" [(ngModel)]="a.Val" type="text"></ion-input>

Bind to it with attr prefix - works on custom and native attributes: 使用attr前缀绑定到它-适用于自定义和本机属性:

<ion-input [attr.maxlength]="a.maxlent" [(ngModel)]="a.Val" type="text"></ion-input>

Or just set its value to the interpolated string value of the variable: 或者只是将其值设置为变量的插值字符串值:

<ion-input maxlength="{{a.maxlent}}" [(ngModel)]="a.Val" type="text"></ion-input>

Like you can see in Angular 2 docs you can achieve what you're looking for by using the attribute binding like this: 就像您在Angular 2文档中看到的那样,您可以通过使用如下所示的属性绑定来实现所需的功能:

<ion-input type="text" [(ngModel)]="myInput" [attr.maxlength]="maxLength"></ion-input>

Please take a look at the code in this working plunker . 请看一下这个工作插件中的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM