javascript - TypeError: Cannot read property 'http' of undefined -


this question has answer here:

im trying put in rest api, keep getting typeerror.

import { component, oninit, inject, injectable } '@angular/core'; import { authservice } "../core/auth.service"; import { httpclient, httperrorresponse } '@angular/common/http'; import * firebase 'firebase/app'; //firebase sdk  @injectable() export class loginservice implements oninit {    constructor(public auth: authservice, private http: httpclient) {    }   ngoninit() {   }    lastlogin() {     firebase.auth().currentuser.getidtoken(true).then(function(idtoken) {       // send token backend via https       //console.log(idtoken);       const req = this.http.put('https://dev-api.byrd.news/v1/login', {         user_token: idtoken       })       .subscribe(         res => {           console.log(res);         },         err => {           console.log("error skete");         }       );     });    } } 

i call function logging lastlogin of user, date , if succes. doing through firebase, , should receive idtoken according docs: https://firebase.google.com/docs/auth/admin/verify-id-tokens

what doing wrong?

on line:

firebase.auth().currentuser.getidtoken(true).then(function(idtoken) { 

change anonymous function arrow-function:

firebase.auth().currentuser.getidtoken(true).then((idtoken) => { 

this let this instance of loginservice inside function.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -