I have some code that updates AngularJS $ area properties. If this code is run in a function, the web page is updated immediately. However, the same code when working inside the SignalR callback function will not immediately refresh the web page.
Code that immediately binds bindings:
HTML with Angular bindings:
<input id="name" type="text" ng-model="playerName" /><button ng-click="RegisterPlayer();">Register</button>
Function inside Angular controller:
$scope.RegisterPlayer = function () {
$scope.numberOfPlayers += 1;
var player = {
name: $scope.playerName,
randomNumber: 0,
totalScore: 0
}
$scope.players.push(player);
}
When this is done, the number of players immediately opens on the web page.
This is how I reorganized the code to send information to the SignalR hub, and then used the same code in the SignalR callback:
These are the same functions as above, but now it just sends information to the SignalR hub:
$scope.RegisterPlayer = function () {
hub.server.send($scope.playerName, -1);
}
( , ):
function receiveSignalRMessage(name, message) {
var randomNumber = parseInt(message, 10);
if (randomNumber == -1) {
$scope.numberOfPlayers += 1;
var player = {
name: $scope.playerName,
randomNumber: 0,
totalScore: 0
}
$scope.players.push(player);
return;
}
}
, , - . , , . ?