首页 > 解决方案 > 无法在 Angular 的 ng-bind 中将数据传递到控制器

问题描述

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

  };

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

标签: angularjs

解决方案


试试这个,在 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);

  };

推荐阅读