如何在不更改下拉列表模型值的情况下从下拉列表绑定的文本框中获取模型值

How to get model value from textbox which is binded from dropdown without changing the model value of dropdown

在我的项目中,我在 Angular html 页面中有一个下拉菜单和一个文本框。 从下拉列表中我 select 一个选项,在 select 那个选项之后它被绑定到文本框。稍后我需要更改文本框的值并提交。我需要点击按钮提交的最新更改值。 如何获取提交时的最新值?

<select ng-model="val" ng-change="select(val);" ng-options="gro.name for gro in group"></select>

<input type="text" value="{{val.name}}" /> 

请帮忙。

使用 ng-model 而不是值

在HTML

<select ng-model="val" ng-change="select(val);" ng-options="gro.name for gro in group"></select>

<input type="text" ng-model="selectedValue" /> 

在控制器发生变化时,(即 ng-change)这将被调用并更新。

function select(val) {
$scope.selectedValue = val;
}

稍后如果您在文本框中更改,ng-model 值(即 selectedValue)将绑定到最新值并且不会在下拉列表中更改,因为下拉列表 ng-model 不同(即 val ).