无法在Angular中的ng-bind中将数据传递到控制器中

时间:2019-02-13 11:00:51

标签: angularjs

我已使用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);

  };

有人可以帮助我解决此问题吗?谢谢提前

2 个答案:

答案 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>