Get old value and new value from dropdown

泄露秘密 提交于 2019-11-30 20:32:51

Try like this

View

<select ng-model="selected" ng-change="change(selected, {{selected}})">

JS

$scope.change = function(newObj, oldObj){
   console.log(newObj);
   console.log(oldObj);
}

you could use ng-click, since click happens before change you could there register the old value like this

<select ng-model="selected" ng-change="change(selected, oldValue)" ng-click="oldValue = selected">

and in the controller

$scope.change = function(newValue, oldValue){
    //do if's in case you use null or empty values
    if ( oldValue ) {
        //do something
    }   
    if ( newValue ) {
        //do something
    }
}

Do it like this:

$scope.$watch('user.group_name', function(newValue, oldValue){

});

No need to use ng-change any more

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!