我定义了以下控件:
<input id="inputSearchMovies"
type="search"
ng-model="filterItems"
placeholder="Search for movies ..."
typeahead="prediction for prediction in getPredictions($viewValue) | limitTo:10"
typeahead-min-length='1'
typeahead-on-select='onSelectPart($item, $model, $label)'
typeahead-template-url="customTemplate.html"
class="form-control shortInputSearch"
style="width: 98% !important" />
这是自我引导到getPredictions
函数,在我输入时执行调用。
问题是输入空格时没有调用预先输入机制:
如何修复它以对每个字符更改(空白或不空白)执行调用?
答案 0 :(得分:2)
你的问题实际上并非来自ui-bootstrap
,它来自角度处理input
的方式。在设置input
的值之前,它会自动修剪ng-model
的值。由于该值最终与以前相同(因为它被修剪),因此它不会认为这是值的变化,因此它不会调用ngModelController
{ {1}},$parsers
用于触发其&#34; getMatchesAsync&#34; (或者你的&#34;先行机制&#34;)。
不用担心,可以使用ui-bootstrap
关闭此功能,如下所示:
ng-trim
此处位于参数<input typehead... ng-trim="false"></input>
下的角度文档中:https://docs.angularjs.org/api/ng/input/input%5Btext%5D
如果设置为false,Angular将不会自动修剪输入。输入[type = password]控件将忽略此参数,这些控件永远不会修剪输入。 (默认值:true)
我知道标题是ngTrim
,但我查看了角度代码,此属性也适用于type=text
。如果需要,我可以显示此代码。