两个控制器之间的通信,这两个控制器在两个不同或相同的divdes的不同Web浏览器中打开

时间:2016-12-08 12:02:15

标签: javascript php angularjs codeigniter

其实我正在尝试创建像GMAIL这样的收件箱。但是一旦发送者发送该消息,我就无法显示收到的消息。我正在使用angularjs和codeigniter。

我有两个控制器的发送器和接收器。一旦发送者发送消息,我就更新接收器控制器的范围变量。但它没有用。

我的发件人控制器发送消息功能 -

$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;
        });
};

有人请帮助我。

3 个答案:

答案 0 :(得分:1)

我认为这是不可能的,你必须将消息存储在数据库中,然后在angularjs中你必须每分钟做一次请求,例如检查是否有新消息。

答案 1 :(得分:1)

Here the Demo For auto updating the value based on time

I think it will useful for you.once you send the data from sender. receiver need to auto update. it will useful to what need to acheive.

答案 2 :(得分:0)

我建议您跟踪每个选项卡的浏览器会话,然后将邮件推送到该会话的活动选项卡。尝试研究如何在客户端中唯一标识活动的浏览器选项卡并将数据推送到这些选项卡。这可能是你正在寻找的逻辑。因为您不能在不同选项卡的控制器之间共享信息,因为不同选项卡中的应用程序上下文不同。