如何获得场与NG-变化值 [英] How to get the value of a field with ng-change
本文介绍了如何获得场与NG-变化值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何对用户的输入做出反应,在AngularJS NG-改变一个textarea。但我怎么能得到角控制器内部的电流输入?我失去了一些东西,比如 $(这).value的(); jQuery中
<脚本>
angular.module('changeExample',[])
.controller('ExampleController',['$范围',函数($范围){
$ scope.evaluateChange =功能(){
的console.log(我如何获得该领域的当前内容?);
};
}]);
< / SCRIPT>< DIV NG控制器=ExampleController>
< textarea的NG-变化=evaluateChange()ID =NG-变化例1>< / textarea的>
< / DIV>
解决方案
NG-模型
它会存储输入,textarea的值,或选择。
您的HTML应该是这样的:
< DIV NG控制器=ExampleController>
< textarea的NG-模式=myvalue的NG变化=evaluateChange()ID =NG-变化例1>< / textarea的>
< / DIV>
然后在你的控制器,你可以参考与 $ scope.myValue
希望帮助! :)
I know how to react to user input in a textarea with ng-change in AngularJS. But how can I get the current input inside the Angular controller? I am missing something like $(this).value();
in jQuery.
<script>
angular.module('changeExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.evaluateChange = function() {
console.log("How do I get the current content of the field?");
};
}]);
</script>
<div ng-controller="ExampleController">
<textarea ng-change="evaluateChange()" id="ng-change-example1"></textarea>
</div>
解决方案
ng-model
It'll store the value of an input, textarea, or select.
Your html should be like this:
<div ng-controller="ExampleController">
<textarea ng-model="myValue" ng-change="evaluateChange()" id="ng-change-example1"></textarea>
</div>
Then in your controller you can reference that with $scope.myValue
Hope that helps! :)
这篇关于如何获得场与NG-变化值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文