【发布时间】:2014-10-22 15:29:39
【问题描述】:
我正在使用 Angular 的 typeahead,但遇到了 ngModel 的问题。
这是我的预输入 html
<input
type= "text"
ng-model= "symbol"
placeholder= "begin typing"
typeahead= "hit.message for hit in getTypeAheadContents($viewValue)"
typeahead-loading= "loadingSymbols"
typeahead-editable= "false"
typeahead-on-select= "onSelect($item, $model, $label)"
typeahead-min-length= 2
typeahead-wait-ms= 500
class= "form-control"
/>
<input ng-click= "search()" value= "Search!"/>
这是我的控制器中的代码(暂时很基础)
$scope.search = function(){
alert($scope.symbol);
}
现在,自动完成代码按预期工作,但是当我单击搜索按钮时,我收到警告消息“未定义”
更奇怪的是我尝试设置
$scope.symbol = "";
在我的控制器的开头,当我点击搜索按钮而不在我的预输入中输入任何内容时,我收到了空字符串提醒我,正如预期的那样。但是,当我在预输入中输入一些内容并再次点击搜索时,我再次返回“未定义”。很明显,angular 的 typeahead 与 ng-model 配合得不是很好,但我不知道该怎么做。
建议?
【问题讨论】:
标签: angularjs angularjs-scope undefined typeahead angular-ngmodel