2016-12-08 7 views
0

実際にGMAILのような受信トレイを作成しようとしています。しかし、送信者がそのメッセージを送信するとすぐに受信したメッセージを表示することはできません。私はangularjsとcodeigniterを使用しています。異なる2つの異なるウェブブラウザで開いている2つのコントローラ間の通信

私は2つのコントローラの送信側と受信側を持っています。送信者がメッセージを送信するとすぐに、私は受信機コントローラのスコープ変数を更新しています。しかし、それは動作していません。

マイ差出人コントローラ、メッセージ送信機能 - 私は私の受信機コントローラスコープを更新したい、その関数の後

$scope.send_message_toCustomer = function(counselor_id,thread_title) { 
    var thread_id=$('#threadid').val(); 
    //console.log(thread_id); 
     $scope.inboxMessage.message=$scope.message; 
     $scope.inboxMessage.thread_id=thread_id; 
     var request = $http({ 
      method:"POST", 
      url: site_url+"thread/insert_thread_message", 
      data : $scope.inboxMessage, 
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' }  
     }); 
     request.success(function($data){ 
       //console.log($data); 
       if($data==1) 
      { 
       $scope.message=''; 
          getCustomerChildThread.getChildThread().success(function($data) 
       { 
        //console.log($data); 
        $scope.C_Thread = angular.copy($data);    
       }); 
       $('#inbox_sub_menu').css('display', 'block'); 
       $('#s_menu').addClass('open'); 
       //$timeout(function() { 
        $scope.inbox_aco_thread.thread_id=thread_id; 
        var request = $http({ 
         method:"POST", 
         url: site_url+"thread/inbox_thread", 
         data : $scope.inbox_aco_thread, 
         headers: { 'Content-Type': 'application/x-www-form-urlencoded' }  
        }); 
        request.success(function($data){ 
          $('#thread_msg_count_'+thread_id).removeClass('msg_count'); 
            $scope.inbox_messages=angular.copy($data); 
            $scope.inbox_messages.counselor_id=angular.copy(counselor_id); 
            $scope.inbox_messages.thread_id=angular.copy(thread_id); 
            $scope.inbox_messages.thread_title=angular.copy(thread_title); 
          }); 
          //}, 500); 
         } 
        }); 

       }; 

。受信機コントローラがメッセージを受信する -

$scope.inbox_cust_thread=function(customer_id,thread_id,thread_title) 
{ 
    $('#thread_msg_count_'+thread_id).removeClass('msg_count'); 
    $scope.main_threadview=true; 
    $scope.add_threadview=false; 
    $scope.cust_thread.loading = false;     
    $scope.inbox_cu_thread.counselor_id=counselor_id; 
    $scope.inbox_cu_thread.thread_id=thread_id; 
    var request = $http({ 
       method:"POST", 
       url: site_url+"Customer_thread/inbox_thread", 
       data : $scope.inbox_cu_thread, 
       headers: { 'Content-Type': 'application/x-www-form-urlencoded' }  
      }); 
      request.success(function($data){ 
       //$('#thread_msg_count_'+thread_id).addClass('msg_count'); 
       $scope.cust_inbox_messages=$data; 
       $scope.cust_inbox_messages.customer_id=customer_id; 
       $scope.cust_inbox_messages.thread_id=thread_id; 
       $scope.cust_inbox_messages.thread_title=thread_title; 
       //$scope.cust_inbox_messages.counselor_id=counselor_id; 
     }); 
}; 

誰かが私を助けてください。

+0

チェック....それはuはあなたのコードを投稿する場合は、本当に役に立つことや、私たち –

答えて

1

私はそれができないと思います。データベースにメッセージを保存してから、新しいメッセージがあるかどうかを確認するために、毎分分のリクエストをしなければなりません。

+0

にplunkerやバイオリンを作成することになりありがとうございました...!それは今働いている。私はデータベースでそれをやった。 – Kavita

0

各タブのブラウザセッションを追跡し、そのセッションのアクティブなタブにメールをプッシュすることをお勧めします。クライアントのアクティブなブラウザタブを一意に識別し、それらのタブにデータをプッシュする方法を研究してください。これはあなたが探している論理かもしれません。異なるタブのコントローラ間で情報を共有することはできないため、アプリケーションのコンテキストは異なるタブで異なります。 $スコープ変数を更新した後に適用すると

関連する問題