Javascript 未使用uib typeahead显示所选值
我在angularjs应用程序的文本框中使用uib typeahead,如下所示。当我打一些信时,我可以看到建议。但是,如果我选择了其中任何一个选项,则该选项不会显示在文本中(ng模型) 我不确定问题是否出在我正在使用的引导版本或角度版本上,或者我在代码中做了一些错误的事情Javascript 未使用uib typeahead显示所选值,javascript,angularjs,twitter-bootstrap,angular-ui-bootstrap,Javascript,Angularjs,Twitter Bootstrap,Angular Ui Bootstrap,我在angularjs应用程序的文本框中使用uib typeahead,如下所示。当我打一些信时,我可以看到建议。但是,如果我选择了其中任何一个选项,则该选项不会显示在文本中(ng模型) 我不确定问题是否出在我正在使用的引导版本或角度版本上,或者我在代码中做了一些错误的事情 <input type="text" ng-model="selectedData" uib-typeahead="proDesc as mydata.proDescription for mydata in data
<input type="text" ng-model="selectedData" uib-typeahead="proDesc as mydata.proDescription for mydata in dataList | filter:$viewValue | orderBy:orderByStartsWith($viewValue)"/>
下面是我代码的链接
您的问题是,当您选择一个选项时,整个对象被分配给输入的
$viewValue
,而不是对象的description属性
如果要根据说明设置$viewValue
:
<input type="text" ng-model="selectedData" uib-typeahead="proDesc as mydata.proDescription for mydata in dataList | filter:$viewValue | orderBy:orderByStartsWith($viewValue)"/>
致:
cnorthfield的解决方案应该有效。然而,在我自己的项目中,由于一些未知的原因,它不起作用。我最终找到了另一个解决方案:
<input type="text"
ng-model="selectedData"
typeahead-input-formatter="$model.proDescription "
uib-typeahead="mydata as mydata.proDescription for mydata in dataList | filter:$viewValue" />
只有在cnorthfield的方法不适用于您时,才应将此方法视为备份计划。我在您的plunker中看到一个错误,即Bootstrap的JavaScript需要jQueryadd jQuery并重试
<input type="text"
ng-model="selectedData"
typeahead-input-formatter="$model.proDescription "
uib-typeahead="mydata as mydata.proDescription for mydata in dataList | filter:$viewValue" />
if (typeof selectedData === 'string') {
for (var i in dataList) {
if (dataList[i].proDescription === selectedData) {
// do some things here
}
}
}