Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus after select #185

Open
enriqueavg opened this issue May 14, 2020 · 3 comments
Open

Focus after select #185

enriqueavg opened this issue May 14, 2020 · 3 comments

Comments

@enriqueavg
Copy link

Hi,

Many thanks for develop this component.

I want to use It for select products and then add items to form array. After users select an element we are cleaning items for new request to the api remote data.

I want to add "autofocus" property to input search. I try with this code but this doesn't work.

In html:

<ngx-select [items]="product_items" placeholder="Search..." optionValueField="name" optionTextField="name" [searchCallback]="searchCallback" (typed)="searchProductsTyped.next($event)" (selectionChanges)="addChargeItem($event)" #searchProductsInput>

component.ts:
@ViewChild('searchProductsInput', { static: false }) searchProductsInput: ElementRef;

and then:

this.searchProductsInput.nativeElement.focus();

I get this error:

ERROR TypeError: Cannot read property 'focus' of undefined

Thanks for your help.

@optimistex
Copy link
Owner

@enriqueavg Hi. Try to do it after viewing init
https://angular.io/guide/lifecycle-hooks#afterview

@enriqueavg
Copy link
Author

Thanks for you quickly response =).

Pls, can you give more advices for do that?

@enriqueavg
Copy link
Author

I try this but input focus still doesn't work.

@ViewChild(NgxSelectComponent) ngxSelectComponent: NgxSelectComponent;
ngAfterViewInit () {
    this.ngxSelectComponent.focusToInput();
    console.log('Hello!')
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants