我在angularjs html结构中有两个输入框。
当我单击按钮或标签时,我希望我的文本框的angularjs中的新旧值相同,或者我想比较旧值与新旧值是否相同。
我正在使用角度1.4.7。

<input phone-input ng-show="mode == 'edit'" ng-model="leader.work"/>
<input phone-input ng-show="mode == 'edit'" ng-model="leader.mobile"/>

<a ng-show="mode == 'edit'" ng-click="mode = null;save_profile(leader)" style="cursor: pointer" title="Save">Save</a>

$scope.save_profile = function (leader) {
  /* How to get/compare both text box old and new value are same or not*/
};

最佳答案

尝试这个



function TodoCrtl($scope) {

  $scope.newValue = 'Initial Text';
  $scope.save_profile = function(newvalue, oldvalue) {

    //Here you can access old value and new value from scope.
    $scope.new = 'New Value :' + $scope.newValue;
    $scope.old = 'Old Value :' + $scope.oldValue;

    //After accessing update the scope old value to new value with function parameters
    $scope.newValue = newvalue;
    $scope.oldValue = newvalue;

  };

  $scope.changeValue = function() {

    $scope.newValue = 'Dynamic Change';
  };

}

<!DOCTYPE html>
<html ng-app>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
  <meta charset=utf-8 />
  <title>ng-click</title>
</head>

<body>

  <div ng-controller="TodoCrtl">

    <input type=text ng-model="newValue" ng-init="oldValue=newValue">
    <button ng-click="save_profile(newValue,oldValue)">Save</button>
    <div>{{new}}</div>
    <div>{{old}}</div>

    <br>
    <button ng-click="changeValue()">Change Dynamic</button>

  </div>

</body>

</html>

关于javascript - 我想比较一下angularjs中输入文本框的旧值和新值是否相同?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36100084/

10-10 00:23