My goal is to use websockets to receive someJSON` through and update a table in a directive.
I've created a simple directive :-
app.directive("penaltyTable", function() {
return {
restrict: 'E',
templateUrl: '/Content/AngularPartials/Coach/PenaltyLine.html',
controller: function() {
this.players = [];
var penaltyController = this;
var uri = "ws://localhost.local/api/CoachesTracker/10";
//Initialize socket
var websocket = new WebSocket(uri);
// Error handling stuff here.....
//Socket message handler
websocket.onmessage = function (event) {
var data = JSON.parse(event.data);
penaltyController.players = data;
};
},
controllerAs: 'penaltyTrackerCtrl'
};
});
I've created a simple template PenaltyLine.html
<table class="penalty-table">
<tr ng-repeat-start="player in penaltyTrackerCtrl.players">
<td>{{player.Number}}</td>
</tr>
<tr ng-repeat-end>
<td>{{player.Name}}</td>
</tr>
<table>
My web-socket receives data OK from the server, appears to update the players array however the template is never updated to display new data.
I think I am learning to run before I can walk with angular! Is there something basic I'm missing?