2016-03-07 94 views
2

我在AngularJS應用中實現了pubnub聊天。我下面這個tutorialAngular的Pubnub聊天

的問題是,如果我從頭開始創建一個新的AngularJS應用聊天的作品,但如果我在已經存在的應用程序中實現的代碼我得到這個錯誤:

Missing Callback             pubnub.min.js:1 

我看不到我寫的信息和我應該收到的信息,但我可以發送它們,並且我可以在聊天的另一端看到這些信息。 你知道我該如何解決這個問題?

編輯:這是爲pubnub聊天控制器:

'use strict'; 

angular.module('myApp.appointments', ['ngRoute']) 

.config(['$routeProvider', function($routeProvider) { 
}]) 

.controller('appointmentsCtrl', ["$rootScope", "$scope", "$http", "$timeout", "$cookies", "URL", "Pubnub", function($rootScope, $scope, $http, $timeout, $cookies, URL, Pubnub) { 

    $scope.sortType = 'name'; 
    $scope.sortReverse = false; 

    $scope.sortType_s = 'time'; 

    $scope.filterAppointments = false; 
    $scope.filterDate = ''; 

    $scope.highlightRow = ''; 

    $scope.$on('$routeChangeSuccess', function() { 
     var data = { 
      "token":$cookies.get('userToken'), 
      "hairdresser_id": $cookies.get('userId') 
     }; 

     $http.post(URL.url + 'appointments', data).then(function(res){ 
      $scope.app_list = res.data.appointments; 
      $scope.service_list = res.data.appointment_services; 
      $scope.customers_list = res.data.customers; 
      $scope.pending_number = res.data.pending; 
     }); 

     data = { 
      "token":$cookies.get('userToken'), 
      "hairdresser_id": $cookies.get('userId') 
     }; 

     $http.post(URL.url + 'monthly_earnings', data).then(function(res){ 
      $rootScope.monthly_earnings = res.data.amount; 
     }); 
    }); 

    // Pubnub implementation 
    $scope.channel = "messages-channel"; 
    $scope.uuid = _.random(100).toString(); 
    Pubnub.init({ 
     publish_key: MY_KEY, 
     subscribe_key: SUB_KEY, 
     ssl: true, 
     uuid: $scope.uuid 
    }); 

    $scope.sendMessage = function() { 
     if (!$scope.messageContent || $scope.messageContent === '') { 
      return; 
     } 
     Pubnub.publish({ 
      channel: $scope.channel, 
      message: { 
       content: $scope.messageContent, 
       sender_uuid: $scope.uuid, 
       date: new Date() 
      }, 
      callback: function(m) { 
       console.log(m); 
      } 
     }); 

     $scope.messageContent = ''; 
    } 

    $scope.messages = []; 

    Pubnub.subscribe({ 
     channel: $scope.channel, 
     triggerEvent: ['callback'] 
    }); 

    $scope.$on(Pubnub.getMessageEventNameFor($scope.channel), function(ngEvent, m) { 
     $scope.apply(function() { 
      $scope.messages.push(m) 
     }); 
    }); 

}]); 
+3

顯示一些代碼或創建一個plunker,以便人們可以幫助您調試您的問題。 –

+0

分享一些代碼。 –

+0

我編輯了這個問題,讓我知道如果你需要更多的信息! – ste

回答

3

您在triggerEvents聲明中Pubub.subscribe功能到底忘了s

Pubnub.subscribe({ 
    channel: $scope.channel, 
    triggerEvents: ['callback'] 
}); 

設我知道它是否解決了你的問題。

+1

是的!謝謝!還有另一個錯誤:在這一行 $ scope.apply(function(){ 我忘了申請前面的「$」! – ste