0

我使用了 ng-blur 并使用函数传递数据,但无法在控制器中使用 console.log 打印值

test.template.html

<div class="col-value">
    <input type="text" autofocus="autofocus" style=' box-sizing: border-box; width:50%' ng-blur="saveData()" ng-model="value">%
</div>

test.controller.js

$scope.saveData = function(){

  console.log($scope.value);

  };

有人可以帮我解决这个问题吗?提前致谢

4

2 回答 2

1

试试这个,在 ng-blur="saveData(value)" 函数中传递 ng-model 值。

<div class="col-value">
    <input type="text" autofocus="autofocus" style=' box-sizing: border-box; width:50%' ng-blur="saveData(value)" ng-model="value">%
</div>

$scope.saveData = function(value){

  console.log(value);

  };
于 2019-02-13T11:16:56.577 回答
0

您的代码运行良好。将以下代码段与您的代码进行比较。

var app = angular.module('app', []);

app.controller('MainCtrl', function($scope) {
  
  $scope.saveData = function(){

  console.log($scope.value);

  };
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body  ng-app="app" ng-controller="MainCtrl">
   <div class="col-value">
    <input type="text" autofocus="autofocus" style=' box-sizing: border-box; width:50%' ng-blur="saveData()" ng-model="value">%
</div>
  </body>

于 2019-02-13T11:19:14.847 回答