[英]ionic - Adding a button inside a input field
I'm trying to add a button inside an <ion-input>
but wherever I add it inside the <ion-list>
the button does not show on the screen.我正在尝试在
<ion-input>
添加一个按钮,但是在<ion-list>
添加它的任何地方,该按钮都不会显示在屏幕上。
What I'm trying to do is to show a button "Forgot" on top of the password field aligned to the right.我想要做的是在右侧对齐的密码字段顶部显示一个“忘记”按钮。 Refer screen:
参考画面:
This is my HTML,这是我的 HTML,
<ion-content>
<ion-list class="au-form" inset padding>
<ion-item>
<ion-input type="text" placeholder="Username"></ion-input>
</ion-item>
<ion-item>
<ion-input type="password" placeholder="Password"></ion-input>
<button clear>Forgot</button>
</ion-item>
</ion-list>
</ion-content>
How do I achieve this layout in Ionic 2?如何在 Ionic 2 中实现这种布局?
Fixed in the recent Ionic releases.在最近的 Ionic 版本中修复。 Adding item-right on the button works.
在按钮上添加 item-right 有效。
<ion-item>
<ion-input type="password" placeholder="Password"></ion-input>
<button clear item-right>Forgot</button>
</ion-item>
For ionic 4 it will look a bit different:对于 ionic 4,它看起来有点不同:
<ion-item>
<ion-input type="password" placeholder="Password"></ion-input>
<button clear slot="end">Forgot</button>
</ion-item>
Instead of left and right they introduced start and end values, which make it easier to build interfaces for both left-to-right and right-to-left writing directions他们引入了开始和结束值而不是左右,这使得为从左到右和从右到左书写方向构建界面变得更容易
I have something similar, a disabled input with an enabled icon button next to the input.我有类似的东西,一个禁用的输入,输入旁边有一个启用的图标按钮。 Here is my HTML:
这是我的 HTML:
<ion-item>
<ion-label floating>My Label</ion-label>
<ion-input [disabled]="true" type="text" [(ngModel)]="MyModel"></ion-input>
<button ion-button large clear (click)="doSomething()" item-end>
<ion-icon name="search"></ion-icon>
</button>
</ion-item>
So in you case, this will work:所以在你的情况下,这将起作用:
<ion-item>
<ion-label>Your Label</ion-label>
<ion-input type="text" [(ngModel)]="yourModel"></ion-input>
<button ion-button large (click)="doSomething()" item-end></button>
</ion-item>
item-left
and item-right
directional properties are deprecated according to https://ionicframework.com/docs/theming/rtl-support/根据https://ionicframework.com/docs/theming/rtl-support/不推荐使用
item-left
和item-right
方向属性
try using flex
:尝试使用
flex
:
<ion-content>
<ion-list class="au-form" inset padding>
<ion-item>
<ion-input type="text" placeholder="Username"></ion-input>
</ion-item>
<ion-item>
<div style="display:flex">
<ion-input type="password" placeholder="Password"></ion-input>
<button clear>Forgot</button>
</div>
</ion-item>
</ion-list>
</ion-content>
Toggling the password visible on and off is simple in ionic 4.在 ionic 4 中,打开和关闭密码可见很简单。
you have to mention the slot value as end ( slot="end"
) to make the icon at end along with item-end
property您必须将槽值提及为 end (
slot="end"
) 以使图标位于 end 和item-end
属性
<ion-item>
<ion-label position="floating">Password</ion-label>
<ion-input type="{{showPass ? 'text' : 'password'}}"></ion-input>
<ion-icon item-end slot="end" name="{{showPass ? 'eye' : 'eye-off'}}" (click)="showPass=!showPass"></ion-icon>
</ion-item>
inside the component.ts file在 component.ts 文件中
showPass:boolean = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.