0

I am integrating quickblox sdk into ionic 2 app. i am not able to get json object from retrieveChatDialogs function below but in response i receive server spi response but the variable chats scope print blank object in console log. I am new to typescript 2 and angular 2 please help.

export class Quickblox {
public chats: any; dialogs: any = {};
    retrieveChatDialogs() {
      var _that = this;
       _that.chats = _that.getdialoglist();
       console.log( _that.chats);
    }
    getdialoglist(){
        var chatdialog:any;
        chatdialog  = QB.chat.dialog.list(null, function (err, resDialogs) {
          if (err) {
            console.log(err);
            chatdialog = {};
          } else {
            chatdialog = resDialogs.items;
          }
        });
          console.log(chatdialog);
        return chatdialog; 
  }

}
cakedev
  • 65
  • 1
  • 7
  • The function is async, so `console.log(chatdialog);` will prints blank, of course. Read [**this**](http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron) topic for more info. – developer033 Nov 21 '16 at 14:17
  • thanks this help me !! – cakedev Dec 27 '16 at 07:23

1 Answers1

0

Try this:

retrieveChatDialogs() {
    var _that = this;
    _that.chats = _that.getdialoglist(function (){
         console.log( _that.chats);
    });
}
Rahul
  • 334
  • 1
  • 8