如何獲得角度預先輸入的先前值 - how to get previous value in angular 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?

我在輸入元素中使用了typeahead。在更改時,我可以通過使用typeahead-on-select從$ item獲取當前值。如何獲得以前的價值?

I have tried ng-click to set the old value

我嘗試過ng-click來設置舊值

<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.

但是,在預先輸入中,您也可以通過退格來更改值,這次舊值仍將來自ng-click。

1 个解决方案

#1


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

您可以使用$ scope.watch獲取新舊值

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

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复