Regression: ngModel doesn't work with search function bind(this) ([ngbTypeahead]="search.bind(this)")
See original GitHub issueBug description:
In case if I use search.bind(this)
ngModel isn’t working, data isn’t set to model
html:
<input
id="typeahead-basic"
type="text"
[ngbTypeahead]="search.bind(this)"
class="form-control"
[(ngModel)]="model"/>
ts:
search(text$: Observable<string>) {
return text$.pipe(
debounceTime(200),
distinctUntilChanged(),
map(term => term.length < 2 ? []
: this.states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10))
)
}
This was working on v/7.0.0
Link to minimally-working StackBlitz that reproduces the issue:
https://angular-dd3z93.stackblitz.io
Versions of Angular, ng-bootstrap and Bootstrap:
Angular: 11.2.7
ng-bootstrap: 9.1.0
Bootstrap:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:26
Top Results From Across the Web
Template parse errors: Can't bind to 'ngbTypeahead' since it ...
Show activity on this post. I get the error "Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of...
Read more >Using the ng-BootStrap TypeAhead Control with Dynamic Data
The control is data bound to the Artist in the model (the [(ngModel) attribute) and when the type ahead control expects to search...
Read more >angular/angular - Gitter
I am trying to include topology.feature but I am not able to display basic map. I read through the documentation but not able...
Read more >Angular Ngbtypeahead Doesn't Reset Value Of Input On Blur
installing ng bootstrap ng add ngbootstrap ngbtypeahead angular ... clear input on blur Regression: ngModel doesn't work with search function bindthis.
Read more >Angular error Can't bind to 'ngModel' since it isn't a ... - YouTube
Learn Angular in Mumbai offline http://stepbystepschools.net/For more such videos visit http://www.questpond.comSee our other Step by Step ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@KyleThenTR To keep things short, my scenario consisted on a table with rows rendered via a ngFor. Each row had a typeahead. I passed a parameter to each typeahead to allow them to know which row they corresponded to. To avoid passing a parameter, I simply encapsulated each row into its own Component. That way, the parameter became one of the Input properties of this new Component, so there was no need to use a parameter in the typeahead function; simple grab that information from the Component itself.
The proposed workaround is to use a pure pipe. It’s really suuuuper easy:
with your
typeaheadFunction
being something along the lines ofreally not sure if I’m a fan 🤔