AngularJS - Scope is not what expected inside an ng-click event of ng-repeat
angularjs, angularjs-controller, scope
Solution
Its true that `ng-repeat` creates a new scope. But you cannot access that scope by doing $scope inside your controller. Instead you can do as below:
<button ng-click="send(message)">Send</button>
And in your JS:
$scope.send = function(message){
alert(message.text);
};
Problem
I have this code snippet: ``` <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); }; ``` I do not understand why: ``` alert($scope.message.text); ``` does not work. I thought that ng-repeat was creating a new scope.