Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49236

Return from function doesn't work

$
0
0

@contrasto97 wrote:

Hi, im tryng to get the response from this http get but it give me this error:


vendor.js:1823 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'subscribe' of undefined
TypeError: Cannot read property 'subscribe' of undefined

here’s my function code

getChatId(emailTo): any {
    var email = emailTo

    const httpOptions = {
      headers: new HttpHeaders({
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Token': this.token_value
      })
    };

    this.httpClient.get("https://xxxx=" + email, httpOptions)
      .subscribe(data => {
        console.log(data['_body']);
        return data
      }, error => {
        console.log(error);
        return error
      });
  }

this inside my constructor

this.getChatId(this.emailTo).then((date) => {

      var docRef = firebase.firestore().collection("xxx").doc(date.response);

      docRef.onSnapshot((doc) => {
        this.document = doc.data()

        let chats_message = [];
        for (let k in this.document.messages) {
          chats_message.push(this.document.messages[k]);
        }
        chats_message.sort(function (a, b) { return a.id - b.id; })
        this.messages_chat = chats_message;
        this.content.scrollToBottom(300);//300ms animation speed

        console.log("Array", this.messages_chat);
      })
    });

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49236

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>