I'd like to attach an google.maps.places.Autocomplete
to an ion-input
, but in Ionic2 ion-input
wraps the <input>
element and I can't figure out how to get access to it.
I've tried creating a directive and using the passed in ElementRef
import {Directive, ElementRef, Input} from 'angular2/core';
@Directive({
selector: '[location-picker]'
})
export class LocationPicker {
constructor(el: ElementRef) {
console.log(el.nativeElement);
}
}
but nativeElement
returns the wrapped input.
<ion-input location-picker="">
<input class="text-input ng-valid ng-dirty ng-touched" type="text" placeholder="" aria-labelledby="lbl-6" location-picker="" autocomplete="off" autocorrect="off">
<!--template bindings={}-->
<!--template bindings={}-->
<!--template bindings={}-->
</ion-input>
I've also tried creating a custom component similar to this and switching Searchbar
to TextInput
, but TextInput doesn't have
.inputElement`.
Any ideas would be welcome.
Thanks!
Ionic still uses an actual <input type="text"> HTML element within the component, however, with Ionic wrapping the native HTML input element it's better able to handle the user experience and interactivity. Similarly, <ion-textarea> should be used in place of <textarea> .
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.
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.
Not sure this is what you're looking for (don't know Ionic)
<ion-input location-picker="">
<input #myInput class="text-input ng-valid ng-dirty ng-touched" type="text" placeholder="" aria-labelledby="lbl-6" location-picker="" autocomplete="off" autocorrect="off">
<!--template bindings={}-->
<!--template bindings={}-->
<!--template bindings={}-->
</ion-input>
@ViewChild('myInput') input;
ngAfterViewInit() {
console.log(this.input.nativeElement.value);
}
See also angular 2 / typescript : get hold of an element in the template
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