Typeahead - ngModel vs SelectedItem
See original GitHub issueCurrently, if you have <input [(ngModel)]="model" [ngbTypeahead]="fn">
, then the model
property is a string while you are typing in the input and an Object
once you select a value (depending on the type of objects you return from your typeahead).
I think it would be good if we separate these two somehow. This is only my opinion/proposition, but it seems that ngModel
could be bound the selected object from the typeahead whereas we could receive the changes to the input in another event if necessary.
I would be interested to know what others think. Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How can I capture NgbTypeahead SelectedItemEvent?
I am unable to bind selected item event with typeahead control. ... protocol and separate out [(ngModel)] into [ngModel] and (ngModelChange).
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 >UI Bootstrap - AngularUI
This repository contains a set of native AngularJS directives based on Bootstrap's markup and CSS. As a result no dependency on jQuery or...
Read more >Value Binding - DropDownList - Kendo UI for Angular - Telerik
When the selected item is an object, always specify valueField . ... If the value which is assigned through the [value] or [(ngModel)]...
Read more >Angular Material - Autocomplete - Tutorialspoint
<md-autocomplete> can be used to provide search results from local or remote data sources. md-autocomplete caches ... A model to bind the selected...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
selectItem
does not works for me.I have as dropdown model
{type: "query", value: "some test value"}
html
So, when you type, the model will be a string. When you select an item, it will run
selectItem
function and you expect it should setform.query
to the stringitem.value
, but instead of thatform.query
will be whole object{type: "query", value: "some test value"}
. I think it is because of this code:when closing the drowpdown, it will set object as a model.
But, when you use
event.preventDefault();
, it will set correctlythis.form.query
, but input value will be cleared/empty, so next time you focus on input, also the model will be cleared.I think that we are going to leave it as-is due to the following reasons:
[editable]="false"
option to skip propagation to the model values entered by the userselectItem
event to have an event fired when users make a selection - in this sense separation already exists.I’m going to close this one as I believe that we’ve got all the necessary mechanisms in place. Happy to re-consider if you think that we can do better and: