微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

原文地址:https://www.jb51.cc/js/159132.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐