javascript – 无法打印来自ngRepeat’ed`textarea`的数据

前端之家收集整理的这篇文章主要介绍了javascript – 无法打印来自ngRepeat’ed`textarea`的数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的Plunker: https://plnkr.co/edit/rBGQyOpi9lS0QtnCUq4L

我想在每个textarea标签中输入console.log().键入textarea会触发printStuff()函数

$scope.printStuff=  function(customize,item){
            console.log(customize[item.index].data);
        };

当我开始输入任何textarea时,我收到此错误

angular.js:14290 TypeError: Cannot read property 'data' of undefined
    at b.$scope.printStuff (index.html:31)
    at fn (eval at compile (angular.js:15118),<anonymous>:4:299)
    at b.$eval (angular.js:17922)
    at angular.js:25653
    at Object.<anonymous> (angular.js:28429)
    at q (angular.js:325)
    at Object.$$writeModelToScope (angular.js:28427)
    at angular.js:28420
    at g (angular.js:28339)
    at f (angular.js:28322)

我该如何解决这个错误

更新了MannFromReno的答案

我仍然得到错误.这是我的Plunker:https://plnkr.co/edit/WwC3kNiTQzaQfjp40h2a

解决方法

我不知道你在哪里得到索引属性.你可以使用$index(由ng-repeat提供).

查看更新的plunker:https://plnkr.co/edit/rOTUoLDWX195Uh0JBXwj

这就是你想要的行为,我是对的吗?

猜你在找的JavaScript相关文章