Hi all,

 I was working on a prototype in angularjs and the code is something as 
below

.controller('HomePageController',['UserService','socket',function(UserService,socket)
             {
                this.userservice = UserService;
                socket.on('messagetoyou',function(data){
                    console.log('obtained data for only me yaaay: ',data);
                });
             }])

*Controller.js*

     .factory('socket',function($rootScope){
                var socket;
                return{
                    getsocket:function()
                    {
                      return socket;
                    },
                    createsocket:function()
                    {
                      socket = io.connect('http://localhost:3000');
                    },
                    on:function(eventName,data){
                        socket.on(eventName,data);
                    },
                    emit:function(eventName,data){
                        socket.emit(eventName,data);
                    }
                };

            })

*Service.js*

My Query is  everytime I reload my page, the controller gets initialized 
and my factory also gets initialized. Is there a way to create factory only 
once?

Thanks,
Giri 

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to