NG-变化获得新的价值和原始值 [英] ng-change get new value and original value
问题描述
我使用的是NG-选项可供选择下拉值。我希望能够在旧值进行比较,以新的价值。 NG-变化可以很好地用于抓拉的新的价值了,但我怎么能得到两个新的价值与原价值?
I'm using ng-options to select values from a pulldown. I'd like to be able to compare the old value to the new value. ng-change works well for grabbing the new value of the pull down, but how can I get both the new value and the original value?
<select ng-change="updateValue(user)" ng-model="user.id" ng-options="user.id as user.name for user in users"></select>
例如,假设我想控制器日志,你以前user.name是比尔,你当前的用户名是PHILLIPE。
For instance, let's say I wanted the controller to log, "Your former user.name was BILL, your current user name is PHILLIPE."
推荐答案
通过角{{EX pression}}您可以添加老用户或user.id价值的NG-改变属性为文字字符串
With an angular {{expression}} you can add the old user or user.id value to the ng-change attribute as a literal string:
<select ng-change="updateValue(user, '{{user.id}}')"
ng-model="user.id" ng-options="user.id as user.name for user in users">
</select>
在ngChange,第一参数updateValue将是新的用户价值,第二个参数将是在选择标签最近一次被更新的角度,与老user.id值形成文字。
On ngChange, the 1st argument to updateValue will be the new user value, the 2nd argument will be the literal that was formed when the select-tag was last updated by angular, with the old user.id value.
这篇关于NG-变化获得新的价值和原始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!