找到你要的答案

Q:how to get previous value in angular typeahead

Q:如何获得角typeahead以前的值

I have used typeahead in input element. On change, I can get the current value from $item by using typeahead-on-select. How to get the previous value?

I have tried ng-click to set the old value

<input type="text"
    ng-model="personDetail.brandchainname"
    typeahead-on-select="redeReferenceId($item, $model, $label, personDetail.id, oldValue)"
    ng-click="oldValue = personDetail.brandchainname"
    typeahead="data as data.name for data in brandChainNames | filter:$viewValue"
    typeahead-editable= 'false'>

However, in a typeahead, you can change the value by backspacing as well and this time the old value will be still from ng-click.

我在输入元素中使用typeahead。在改变,我可以用美元typeahead选择项目得到的电流值。如何获取以前的值?

我已经尝试NG点击设置旧值

<input type="text"
    ng-model="personDetail.brandchainname"
    typeahead-on-select="redeReferenceId($item, $model, $label, personDetail.id, oldValue)"
    ng-click="oldValue = personDetail.brandchainname"
    typeahead="data as data.name for data in brandChainNames | filter:$viewValue"
    typeahead-editable= 'false'>

然而,在typeahead,你可以通过回退以及这次旧的价值仍将从NG点击更改值。

answer1: 回答1:

You can use $scope.watch for getting new and old value

 $scope.$watch('field', function (newVal, oldVal) {
   // your task
}

你可以使用scope.watch美元获得新的和旧的价值

 $scope.$watch('field', function (newVal, oldVal) {
   // your task
}
javascript  angularjs