私はこのコードスニペットを持っています:
<ul>
<li ng-repeat="message in messages">
<button ng-click="send()">Send</button>
</li>
</ul>
$scope.send = function(){
// not working (message undefined)
alert($scope.message.text);
// working
alert($scope.messages[0].text);
};
私はなぜなのか理解していない:
alert($scope.message.text);
動作しません。ng-repeat が新しいスコープを作成していると思いました。