Kiran Kumar Kiran Kumar - 4 months ago 78
AngularJS Question

Send selected typeahead option through typeahead-on-select

<input type="text"
class="topic_select"
id="selectTopic"
ng-model="topicsPopulate"
uib-typeahead="topic.name for topic in topics|filter:$viewValue"
uib-typeahead-show-hint="true"
uib-typeahead-min-length="1"
typeahead-on-select="TopicChanged(topicsPopulate)" />


I actually want to send the topic(a json object with many variables) i selected and not the string(topic name) which is stored in
topicsPopulate
.
Topics is an array of topic, and a topic looks like this,

{
id: "12967",
name: "ABCD",
description: "ABCD"
}

Answer

uib-typehead follows the same syntax as Angular ng-options. So just alter your uib-typehead:

uib-typeahead="topic as topic.name for topic in topics|filter:$viewValue"

Please look at the Plunker.