Is there any way to refresh a controller in Angular? Consider the following example:
<div ng-controller="MsgCtrl" ng-repeat="m in messages">{{m}}<br></div>
<script>
var ws = new WebSocket(something, something);
function MsgCtrl($scope) {
$scope.messages = [];
ws.onmessage = function(e) {
$scope.$apply(function() {
$scope.messages.push(e.data);
});
}
}
</script>
If the websocket connection fails, or has to be restarted for some reason, a new websocket must be created and listened to. Is there any way to force the controller to run again, creating a new listening function to push the new connection's messages into $scope?
Also, as a secondary question: is there a good place to go to learn more about Angular? The documentation on the site seems a little unclear.