I'm using Ionic 2 and on my app I'm creating a form where if there is a validation error, an information icon will appear on the right side of it's relevant input field. The HTML is as follows,
<ion-list inset padding>
<ion-item>
<ion-input type="text" placeholder="Email"></ion-input>
<ion-icon name="ios-information-circle-outline" item-right></ion-icon>
</ion-item>
</ion-list>
This works perfectly fine. But whenever I add an *ngIf onto the ion-icon
, it disappears from the ui. Here is a sample where I've set *ngIf to true to see if it works. The icon does not show.
<ion-list inset padding>
<ion-item>
<ion-input type="text" placeholder="Email"></ion-input>
<ion-icon name="ios-information-circle-outline" item-right *ngIf="true"></ion-icon>
</ion-item>
</ion-list>
When the <ion-input>
is removed from above example, the <ion-icon>
shows.
Is this a restriction in Ionic 2? How do I add an icon inside an ion-item
which contains an ion-input
?
By using [(ngModel)]="value" you bind the value variable to that input field. That way it is always updated. If you change it in the UI, it is immediately updated "in the code". And when you update it in your code, it automatically updates in the UI.
please check this. This is working perfectly for me in ionic2.
<ion-item class="from-group details">
<ion-label fixed>Details</ion-label>
<ion-input type="file"></ion-input>
<ion-icon name="ios-camera-outline" item-right ></ion-icon>
<ion-icon ios="ios-cloud-upload" md="md-cloud-upload" item-right ></ion-icon>
Please try ngClass as a workaround for this issue
<ion-item>
<ion-input type="text" placeholder="Email"></ion-input>
<ion-icon [ngClass]="{'hide': true }" name="ios-information-circle-outline" ></ion-icon>
</ion-item>
<style>.hide { display:none; } </style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With