Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angularjs ng粘贴不更新模型值_Angularjs_Angularjs Scope_Angularjs Ng Model - Fatal编程技术网

angularjs ng粘贴不更新模型值

angularjs ng粘贴不更新模型值,angularjs,angularjs-scope,angularjs-ng-model,Angularjs,Angularjs Scope,Angularjs Ng Model,我已经为textarea使用了ng paste,在textarea中粘贴链接时,我调用了一个自定义函数来存储该值。请参考以下代码 <textarea rows="1" ng-model="myObj.content" ng-paste="getContent(myObj)"> </textarea> $scope.getContent = function(a){ console.log(a.content); } $scope

我已经为textarea使用了
ng paste
,在textarea中粘贴链接时,我调用了一个自定义函数来存储该值。请参考以下代码

<textarea rows="1" ng-model="myObj.content"
              ng-paste="getContent(myObj)">
 </textarea>

$scope.getContent = function(a){
    console.log(a.content);
}

$scope.getContent=函数(a){
console.log(a.content);
}

但在控制台中,我总是得到
未定义的
值。如何获取对象值?

将模型传递给函数实际上没有意义,因为您已经指定了
ng model
,因此当用户在
文本框中键入内容时,它的值将被更新。如果要跟踪更改,可以为您的型号设置
$watch
,或使用
ng change
指定功能

如果你想知道用户粘贴了什么,那就另当别论了。处理ng粘贴可能会很棘手。要访问实际事件,最简单的方法是在
angularjs
之前包含
jQuery
,然后执行以下操作:

HTML模板

<textarea rows="3"
          placeholder="copy/paste here..."
          ng-init="content = null"
          ng-model="content" 
          ng-paste="paste($event.originalEvent)">
</textarea>
我是相关的普朗克



只需使用
$timeout
在模型更新后调用粘贴回调

$scope.getContent = function(a){
   $timeout(function () {console.log(a.content)});
}

编辑了我的答案,希望有帮助!什么是$event.originalEvent责任?
$scope.getContent = function(a){
   $timeout(function () {console.log(a.content)});
}