如何从Ionic2中的离子输入中获取包裹的输入?

cno*_*ris 5 ionic-framework ionic2 angular

我想附加一个google.maps.places.Autocompleteion-input,但在Ionic2 ion-input包装的<input>元素,我无法弄清楚如何访问它.

我已经尝试创建一个指令并使用传入的 ElementRef

import {Directive, ElementRef, Input} from 'angular2/core';

@Directive({
    selector: '[location-picker]'
})

export class LocationPicker {
    constructor(el: ElementRef) {    
        console.log(el.nativeElement);    
    }
}
Run Code Online (Sandbox Code Playgroud)

nativeElement返回包装的输入.

<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>
Run Code Online (Sandbox Code Playgroud)

我还试图建立类似一个自定义组件和切换SearchbarTextInput,但TextInput doesn't have.inputElement`.

任何想法都会受到欢迎.

谢谢!

Gün*_*uer 4

不确定这就是你要找的(不知道 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>
Run Code Online (Sandbox Code Playgroud)
@ViewChild('myInput') input; 

ngAfterViewInit() {
  console.log(this.input.nativeElement.value);
}
Run Code Online (Sandbox Code Playgroud)

另请参见Angular 2 / TypeScript :获取模板中的元素