kadoshms / ionic2-autocomplete

Ionic 2 autocomplete component
MIT License
149 stars 108 forks source link

How to call function after data is selected ? #42

Closed rkmahale17 closed 7 years ago

kadoshms commented 7 years ago

As described in the docs, you can bind the itemSelected event to the component. Example:

<ion-auto-complete [itemSelected]="doSomething($event)" ..... ></ion-auto-complete>

rkmahale17 commented 7 years ago

I tired that solution but it's giving me error....

polyfills.js:3 Unhandled Promise rejection: Template parse errors: Can't bind to 'itemSelected' since it isn't a known property of 'ion-auto-complete'.

  1. If 'ion-auto-complete' is an Angular component and it has 'itemSelected' input, then verify that it is part of this module.
  2. If 'ion-auto-complete' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
  3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
    ][itemSelected]="ionicViewData($event)" #searchbar >
kadoshms commented 7 years ago

Please post your code

rkmahale17 commented 7 years ago

seat.js

import { Component, ViewChild, ElementRef } from '@angular/core'; import { NavController, Platform } from 'ionic-angular'; import { railwayService } from '../../services/rlwyServices'; import { autoForSeat } from '../../services/autoForSeat'; import {AutoCompleteComponent} from "ionic2-auto-complete/dist"; import { Geolocation } from '@ionic-native/geolocation'; import {trainStatus} from '../../pages/trainStatus/trainStatus';

declare var google;

@Component({ selector: 'seat', templateUrl: 'seat.html',

})

export class seat {

       @ViewChild('map') mapElement: ElementRef;

map: any; searchVal: string; railValue:any; @ViewChild('searchbar') searchbar: AutoCompleteComponent; constructor(public navCtr:NavController , public rlwy: railwayService,public autoForSeat: autoForSeat, public geolocation: Geolocation ){

}

ionicViewData(){ this.searchVal =this.searchbar.getValue(); var numb = this.searchVal.match(/\d/g); var sham = numb.join(""); this.rlwy.getRoute(sham); //console.log(this.completeTestService.searchbar );

}

}

seat.html

<ion-auto-complete [dataProvider]="autoForSeat" [ionInput]="ionicViewData()" #searchbar >

kadoshms commented 7 years ago

what version of the plugin are you using?

kadoshms commented 7 years ago

@rkmahale17 I would first recommend you to upgrade the plugin (1.5.0-beta is available).

Secondly, I you should bind the event this way (I edited my previous post): <ion-auto-complete (itemSelected)="doSomething($event)" ..... ></ion-auto-complete>

I by mistake confused between the two ways of binding ( it should be '()' and not '[]')