-
Notifications
You must be signed in to change notification settings - Fork 37
Angular Client
Anders Malmgren edited this page Feb 28, 2019
·
5 revisions
Install the Angular client using
Install-Package SignalR.EventAggregatorProxy.Client.Angular
The library wraps the vanilla client library so you need to add a reference to it.
angular.module("MyApp", ["signalR.eventAggregator"])
.controller("MyController", [
"$scope", "$http", function($scope, $http) {
function onEvent(e) {
//act on event
};
$scope.eventAggregator().subscribe(MyApp.MyEvent, onEvent);
}
]);
NOTE The wrapper listens to scope destroy event and unsubscribes the scope
- First declare an event
MyApp.ClientEvent = function(data) {
this.data = data;
};
- Subscribe to it
$scope.eventAggregator().subscribe(MyApp.ClientEvent, onEvent);
- Publish
$scope.eventAggregator().publish(new MyApp.ClientEvent("data"));