在您的点击表达式中,您可以引用
postText并在您的
savePost函数中对其进行访问。如果这不在ng-
repeat中,则可以
$scope.postText成功访问单个对象,但是ng-
repeat为每个项目创建一个新作用域。
这是更新的小提琴。
<div ng-repeat="post in posts"> <strong>{{post}}</strong> <input type="text" ng-model="postText"> <a href="#" ng-click="savePost(postText)">save post</a></div>$scope.savePost = function(post){ alert('post stuff in textbox: ' + post);}


