Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ion-input inside custom component

Tags:

angular

ionic2

I'm trying to create a custom component in angular2/ionic2 which contains an input, here is the code:

import {Component} from "angular2/core";
import {ItemInput} from "ionic-framework/ionic";


@Component({
    directives: [ItemInput],
    selector: "add-input",
    template: `
    <ion-input clearInput>
      <input type="text" value="">
    </ion-input>
  `
})
export class AddInput {
    constructor() { }
}

The problem is that the ion-input seems to be ignored in the final page/view (no styles applied, can't even click on it). If I move the code as is to the main view, then it works. When adding to this custom component a button like

<button>ok</button> 

and importing Button (and adding it to the directives list of this component too) this works. So I'm not sure if something special has to be done abot the ItemInput component to be used in a custom component, or if I'm just hitting a bug.

Using ionic 2.0 alpha49.

Any clues?

like image 706
Matt Avatar asked Jan 18 '16 07:01

Matt


People also ask

How do you assign a value to an input field in ionic?

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".

How do you make ion input readonly?

Add an ion input tag with conditional readonly <ion-input [readonly]="isReadonly"> Set isReadonly variable to true. readonly attribute is not rendered on the resulting input tag.

What is ionChange?

(ionChange) : This event fires only when user change value of input field. if user copy and paste same value it will not get fired. but if user enters different value then it will fire. because it matters values of input field.


1 Answers

Import ionic directives with IONIC_DIRECTIVES:

import {Component} from '@angular/core';
import {IONIC_DIRECTIVES} from 'ionic-angular';

@Component({
    selector: 'add-input',
    template: `
    <ion-input clearInput>
      <input type="text" value="">
    </ion-input>
    `,
    directives: [IONIC_DIRECTIVES]
})

export class AddInput {
  constructor() {}
}
like image 60
Raphael Avatar answered Sep 25 '22 20:09

Raphael