Trevor Turney Trevor Turney - 6 months ago 19
AngularJS Question

Getting a "Missing Callback" when trying to call functions in pubnub-angular

I'm trying to get a simple chat application running, using PubNub and pubnub-angular. when I try to call

Pubnub.subscribe()
, I get a
Missing Callback
error, referring to line 1 in pubnub.min.js.

Things appear to be set up okay:

app.js:

angular
.module('pnChatApp', [
'ngResource',
'ngRoute',
'pubnub.angular.service'
])
.config(function($routeProvider) {
$routeProvider
.when('/main', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
})
.when('/join', {
templateUrl: 'views/join.html',
controller: 'JoinCtrl',
})
.otherwise({
redirectTo: '/join'
});
});


main.js:

angular.module('pnChatApp')
.controller('MainCtrl', ['$scope', '$rootScope', '$location', 'Pubnub', function($scope, $rootScope, $location, Pubnub) {
...
Pubnub.subscribe({
channel: $scope.controlChannel,
});


and, index.html:

<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/pubnub-angular/dist/pubnub-angular.min.js"></script>


PubNub is getting initialized in another controller, and that happens before I get to this point.

Any thoughts?

Answer

You need to register a callback when you subscribe:

Pubnub.subscribe({
  channel: $scope.controlChannel,
  callback: function (message) {
    console.log(message);
  }
});
Comments