如何将值传递给<textarea>控制器中的函数?



我需要address在JS文件中的控制器函数中的值。我如何得到这个值?它不是在表单中,而是在<div>标签中。

<textarea class="form-control" name="address" placeholder="Type your Address" rows="5"></textarea>
<textarea class="form-control" name="address" ng-model="textContent" placeholder="Type your Address" rows="5"></textarea>

在scope

的帮助下访问控制器
 function ctrl($scope){
      console.log($scope.textContent);
    }

您可以像这样在textarea中使用ng-model

<textarea class="form-control" ng-model="details" name="address" placeholder="Type your Address" rows="5"></textarea>

那么在控制器中你可以像

那样访问它
angular.module('myApp', []).controller('myCtrl', function($scope) {
  console.dir($scope.details);
});

查看angularjs官方文档中的ng-model。你知道吗,这太酷了!

最新更新