我试图使用PubNub和pubnub-angular运行简单的聊天应用程序。当我尝试拨打Pubnub.subscribe()
时,我收到Missing Callback
错误,指的是pubnub.min.js中的第1行。
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,
});
和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 在另一个控制器中初始化,这种情况在我到达这一点之前就已经发生了。
有什么想法吗?
答案 0 :(得分:1)
订阅时需要注册回调:
Pubnub.subscribe({
channel: $scope.controlChannel,
callback: function (message) {
console.log(message);
}
});