Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 - Cannot add an ion-icon inside an ion-item containing a ion-input

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?

like image 820
user3607282 Avatar asked Apr 12 '16 07:04

user3607282


People also ask

How do you set the value of 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.


2 Answers

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>

like image 58
Manish Avatar answered Sep 26 '22 22:09

Manish


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>
like image 44
Mark Timothy Avatar answered Sep 23 '22 22:09

Mark Timothy