这是我的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
这就是你想要的行为,我是对的吗?