我已使用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);
};
有人可以帮助我解决此问题吗?谢谢提前
答案 0 :(得分: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);
};
答案 1 :(得分: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>