Hi, I have socket object in one component, I want to use socket object in other component , so am using services, am setting value into the service and trying to get through another component by using service object it is giving undefined . SO please help me.
below is my sample code.
makeSocketConnection() {
var url = "http://" + this.ip + ":" + this.port + "/";
if(this.socket===undefined||!this.socket.connected){
console.log("establishing socket connection undefined");
this.socket = io(url);
this.socket.emit('add user', this.user);
this.storage.set('socket',this.socket) ;//sets socket object
// this.newMessage();
this.chatService.setSocket(this.socket);//sets socket object
}
}
am setting a socket object by this.chatService.setSocket(this.socket)
and am trying to getin other component like below
`this.storage.get('socket').then((val) => {
console.log(" socket obj is "+val);//giving undefined
});
console.log(" this.dummytest is "+this.chatService.getSocket());--//giving undefined
`