Skip to content

Instantly share code, notes, and snippets.

/1.js

Created December 18, 2013 01:03
Show Gist options
  • Save anonymous/8015653 to your computer and use it in GitHub Desktop.
Save anonymous/8015653 to your computer and use it in GitHub Desktop.
AngularJS and PubNub
<script src="http://cdn.pubnub.com/pubnub.min.js"></script>
<script src="components/angular/angular.js"></script>
<script src="scripts/pubnub-angular.js"></script>
<body ng-app="PubNubAngularApp">
<script src="scripts/app.js"></script>
angular.module('PubNubAngularApp', ["pubnub.angular.service"])
<script src="scripts/controllers/main.js"></script>
.controller('JoinCtrl', function($scope, PubNub) { ... });
$scope.publish = function() {
PubNub.ngPublish({
channel: $scope.selectedChannel,
message: $scope.newMessage
});
};
$scope.subscribe = function() {
...
PubNub.ngSubscribe({ channel: theChannel })
...
$rootScope.$on(PubNub.ngMsgEv(theChannel), function(event, payload) {
// payload contains message, channel, env...
console.log('got a message event:', payload);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment