1.1.0 • Published 4 years ago

ion4-autocomplete v1.1.0

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

Ionic 4 Autocomplete

Autocomplete component for ionic 4.

autocomplete999901aca1eb60ad.gif

Support

  • @ionic/angular 4.0.0

Usage

Installation

npm i ion4-autocomplete

Import Module

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
...
import { AutocompleteModule } from "ion4-autocomplete";
 
@NgModule({
  declarations: [
    MyApp,
    ...
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    AutocompleteModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    ...
  ]
})
export class AppModule {}

NgModel mode

<ion-autocomplete [suggestions]="customers"
                  (itemSelected)="customerSelected($event)"
                  [(ngModel)]="customerId">
</ion-autocomplete>
import { Component } from '@angular/core';
 
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  customers: any[];
  customerId: number;
  selectedCustomer: any;
  constructor() { }
  
  customerSelected(customer) {
    this.selectedCustomer = customer;
  }
  
}

Reactive Forms

<ion-autocomplete [suggestions]="customers"
                  (itemSelected)="customerSelected($event)"
                  formControlName="customerId">
</ion-autocomplete>
import { Component } from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  customers: any[];
  selectedCustomer: any;
  formGroup: FormGroup;
  constructor(private formBuilder: FormBuilder) {
    this.formGroup = this.formBuilder.group({
    customerId: []
    ...
    });
   }
  
  customerSelected(customer) {
    this.selectedCustomer = customer;
  }
  
}

Input Properties

NameTypeDefaultDescription
suggestionsany[]nullList to search
labelFieldstring'name'Label property
idFieldstring'id'Id property
placeholderstring'Search'Placeholder
input valuestring''Original value of input
readonlybooleanfalseDisable component

Output Properties

NameTypeDescription
itemSelectedEventEmitterItem Selected

Thanks for reading

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago