繁体   English   中英

angular-ui引导程序提前输入换码键导致输入字段值未定义

[英]angular-ui bootstrap typeahead escape key causing input field value become undefined

我在解决这个似乎很麻烦的问题时遇到了麻烦。 当我选择(使用键盘或鼠标)从typeahead的下拉列表中选择一个值时,输入字段中的ng-model就会很好地填充。

但是,如果我输入几个字母然后单击“转义”按钮,则由于我未选择值,因此'textFieldValue'ng模型似乎被typeahead覆盖为'undefined'。

解决此问题的最佳方法是什么? 还是太多了?

<input type="text" ng-model="textFieldValue"
typeahead="list for list in getList($viewValue)" typeahead-editable="false">

您可以通过使用临时值来实现。

将温度值分配为提前输入

<input type="text" ng-model="tempValue" typeahead="list for list in getList($viewValue) | filter:$viewValue" typeahead-editable="false" >

监视tempValue并决定是否更新目标值。

    $scope.$watch('tempValue', function(tempValue){
      if(shouldUpdateTheTargetValue(tempValue)) {
        $scope.targetValue = tempValue;   
      }
    });

我为此创造了一个小矮人。 -http://plnkr.co/edit/r63027iRobX4skV9YK60?p=preview

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM