ng-change get new value and original value

前端 未结 7 903
北荒
北荒 2020-11-28 22:20

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 th

7条回答
  •  臣服心动
    2020-11-28 22:44

    You can use a scope watch:

    $scope.$watch('user', function(newValue, oldValue) {
      // access new and old value here
      console.log("Your former user.name was "+oldValue.name+", you're current user name is "+newValue.name+".");
    });
    

    https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$watch

提交回复
热议问题