How can a controller be refreshed in Angular? Take into account the scenario below:
<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 needs to be restarted for any reason, a new websocket must be created and listened to. Is there a way to trigger the controller to run again, creating a new listener to push messages from the new connection into $scope?
In addition, as a follow-up question: Where is a reliable source to expand knowledge on Angular? The documentation on the official site may not provide clear guidance.