ionic ion-searchbar focus 獲取焦點

ionic ion-searchbar 組件獲取焦點方法:

 

import {Directive, Renderer, ElementRef} from "angular2/core";

@Directive({
  selector : '[focuser]'
})

export default class Focuser {
  constructor(public renderer: Renderer, public elementRef: ElementRef) {}

  ngOnInit() {
    //search bar is wrapped with a div so we get the child input
    const searchInput = this.elementRef.nativeElement.querySelector('input');
    setTimeout(() => {
      //delay required or ionic styling gets finicky
      this.renderer.invokeElementMethod(searchInput, 'focus', []);
    }, 0);
  }
}


<ion-searchbar [focuser] placeholder="Enter Your Address"></ion-searchbar>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章