Javascript angular typeahead$viewValue重命名后未更新

Javascript angular typeahead$viewValue重命名后未更新,javascript,angularjs,angular-ui-bootstrap,angular-ui-typeahead,Javascript,Angularjs,Angular Ui Bootstrap,Angular Ui Typeahead,我使用的是angular v.1.2.28,我有一个复杂的元素,它结合了下拉菜单和typeahead: <div class="btn-group vl-dropdown-container " style="width:100%" dropdown ng-class="{disabledFunctionalityAndClick:isReadOnly}"> <a class="vl-dropd

我使用的是angular v.1.2.28,我有一个复杂的元素,它结合了下拉菜单和typeahead:

<div class="btn-group vl-dropdown-container " style="width:100%" dropdown
                     ng-class="{disabledFunctionalityAndClick:isReadOnly}">

                    <a class="vl-dropdown-toggle vl-pf-dd-button" dropdown-toggle>
                        <span class="caret"></span>
                    </a>

                    <div style="overflow: hidden;">
                        <input placeholder="Select a discount table" class="vl-autocomplete  um-dd-input"
                               ng-model="selectedTypeaheadValue"
                               typeahead="discount as discount.id for discount in discountTablePool | filter:$viewValue"
                               typeahead-on-select="selectDiscountTable($item)"
                               typeahead-editable="false"
                               ng-blur="validateSelectedDiscount($viewValue)"/>
                    </div>
                    <ul class="dropdown-menu" role="menu">
                        <li ng-repeat="discountTable in discountTablePool track by $index">
                            <a href dropdown-toggle ng-click="selectDiscountTable(discountTable)">{{discountTable
                                .id}}</a>
                        </li>
                    </ul>

                </div>
问题是模型$scope.selectedTypeaheadValue已更新,但显示给用户的值仍然是上一个值,因此如果我将折扣1重命名为折扣2,则模型将更新,但用户仍会看到折扣1:

您的$scope.selectDiscountTable可能会在摘要周期之外被调用,因为它是从延迟函数内部触发的。由于这不是角度事件,您可能必须手动触发重新摘要以同步视图


尝试使用$scope.$evalAsync并更新其中的$scope值。

显然这是一个简单的解决方案,我所要做的就是将html中的ng模型从:ng model=selectedTypeaheadValue更改为:ng model=selectedTypeaheadValue.id

不确定这是真的,因为它是一个ui引导模式,并且在角度循环中运行。您可以看到,我也在更新其他$scope值,它们更新得很好。
<a class="um-menu-label" ng-click="renameDiscountTable()">Rename              </a>
modalInstance.result.then(function (data) {

                        if ($scope.selectedDiscountTable.id != data.name) {
                            if ($scope.selectedDiscountTable.isFromServer === true) {
                                //check if it was already renamed
                                var obj = _.find($scope.renamedDiscountTables, {newName: $scope.selectedDiscountTable.id});
                                if (obj) {
                                    obj.newName = data.name;
                                }
                                else {
                                    $scope.renamedDiscountTables.push({
                                        oldName: $scope.selectedDiscountTable.id,
                                        newName: data.name
                                    });
                                }
                            }
                            $scope.selectedDiscountTable.id = data.name;
                          //THIS IS WHERE I CHANGE THE TYPEAHEAD MODEL VALUE    
                            $scope.selectDiscountTable($scope.selectedDiscountTable);
                        }


                }


 $scope.selectDiscountTable = function (discount) {
            $scope.selectedDiscountTable = discount;
            $scope.selectedTypeaheadValue = angular.copy($scope.selectedDiscountTable);
        };