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

Typeahead - Change Detection - Not working #536

Closed
webdev48 opened this issue May 24, 2016 · 3 comments
Closed

Typeahead - Change Detection - Not working #536

webdev48 opened this issue May 24, 2016 · 3 comments

Comments

@webdev48
Copy link

Trying to use ng2-boostrap typeahead and trying to clear the model on selection of a suggestion.

 <input [(ngModel)]="selected"
           [typeahead]="moduleNames"
           (typeaheadOnSelect)="typeaheadOnSelect($event);"
           [typeaheadOptionField]="'name'"
           class="form-control">

in component

public typeaheadOnSelect(e:any):void {

        console.log("typeaheadOnSelect ",e.item);
        this.uiBoardServ
            .addModule(e);

        this.selected ='';  // this is never reflected on the UI

    }

the typeahead search box is never cleared even when I am doing this.selected='' . In Angular 1, people solved it in some weird ways: http://stackoverflow.com/questions/22104498/how-to-clear-text-from-angularui-typeahead-input/26793276#26793276

Is this a Angular 2 bug or a ng2-boostrap issue ? Why is change detection not fired ?

Here is a Plnkr to demonstrate the problem:
http://plnkr.co/edit/VWwrMDzISfwfEfwvn1f5?p=preview

@Dinistro
Copy link
Contributor

@webdev48 This looks like an issue in ng2-bootstrap. I will take a look.

@valorkin
Copy link
Member

valorkin commented Jun 6, 2016

Finishing last bit and will publish @Dinistro 's fix for it today

@ked1
Copy link

ked1 commented May 30, 2018

This "fix" actually causes problems in our case.

We need to select "onKeyDown enter". To achieve this, we manually invoke this.typeaheadInstance._container.selectActiveMatch() (Template: #typeaheadInstance="bs-typeahead").

I expect the event listener typeaheadOnSelect(...) to be called. This works "onItemClick" but not in the self-implemented ENTER-Case (selectActiveMatch). The same issue exists by leaving "onKeyDown(tab").

If I temporarily remove the setTimeout in the typeahead-container.component.ts the selection by enter works fine and the typeaheadOnSelect is invoked as expected. Even the "tab" works well.

What am I doing wrong? Is there a known fix?

Thanks in advance!

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

4 participants