I am using Angular-UI typeahead in the following way:
<input type="text" ng-model="myModel" typeahead="o.value as o.text for o in options | filter:$viewValue | limitTo:5" typeahead-editable="false" />
binded to a model like:
var options = [
{"value": 1, "text": "value1"},
{"value": 2, "text": "value2"},
...
];
It correctly shows options text, but when I select an item it shows inside the textbox the value. The model is correctly bounded to the value only (not the entire model object).
Is it possible to show inside the textbox the "text" (not the "value") after selection, still maintaining model binding to just the value (ie: when I select a certain "text" the model is updated with the "value")?
for me this:
instead of:
was really usefull
i had a json made like this:
and it ended up in something like having the dropdown menu with just the RagioneSociale value and a model where i can see both the text and the id and print them with a normal {{asyncSelected}}
You can try doing as suggested but with typeahead-on-select like so
This will ensure that the text or label is displayed but underlying value is changed.
It's not ideal, but the typeahead-input-formatter attribute provides a work-around until a fix can be provided. (Plunker from github thread).
HTML:
AngularJs controller function:
Here a shorthand formatter for everybody who uses lodash or underscore:
and html:
Well, so far I found a possible solution through directives.
HTML
DIRECTIVE
Well... obviously this is only a trick... I would like to know if is there a cleaner, more natural way to do it... without modifying code or using directive...
Try changing your code from
to