I am new to AngularJS.
I have a PHP script which returns data in JSON format. I handle that response like so:
<div ng-app="myApp" ng-controller="gameCtrl">
<table>
<thead>
<tr>
<th class="medium">Date</th>
<th class="small">Time</th>
<th class="medium">Location</th>
<th class="medium">Opponents</th>
<th class="medium">Result</th>
</tr>
<tr ng-repeat="x in games">
<td>{{ x.GameDate }}</td>
<td>{{ x.GameTime }}</td>
<td>{{ x.GameLocation }}</td>
<td>{{ x.Opponents }}</td>
<td class="game-info" data-game-id=""{{ x.GameID }}"">{{ x.Outcome === null ? "" : x.Outcome + ' ' + x.Score }}</td>
</tr>
</thead>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('gameCtrl', function($scope, $http) {
$http.get("script.php")
.success(function(response) {$scope.games = response.games;});
});
</script>
If you notice the
<td class="game-info"
part I would like to respond to that cell click. I have the necessary jquery code:
$('.game-info').on('click', function()
{
console.log('game info clicked');
// snip
}
however that code is never run. If I have the td outside of the Angular div then it works as expected.
In short how can I listen for a click event using jquery from an element in an Angular block?
ng-clickas opposed tojQuery, for several reasons. docs.angularjs.org/api/ng/directive/ngClickng-clickwhich is theAngularway?<a ng-click="doSomething(argument)">, then in controller$scope.doSomething = function (parameter) { .. };