javascript - Access constructor parameters inside the google sign in function Angular 2 -


i translate google sign in javascript typescript, , works, issue i'm having cannot access _router variable inside google sign in function. inside attachsignin() function try access _router: router param constructor , undefinded.

this code

import {component, ngzone} "angular2/core"; import {toastsmanager } 'ng2-toastr/ng2-toastr'; import {router, router_providers} 'angular2/router'  // google's login api namespace declare var gapi: any;  @component({     selector: "sous-app",     templateurl: "app/login/login.html",     providers: [toastsmanager, router_providers] }) export class login {     googleloginbuttonid = "google-login-button";     userauthtoken = null;     userdisplayname = "empty";     auth2 = null;     self = this;       constructor(         public _router: router) { }      // angular hook allows interaction elements inserted     // rendering of view.     ngafterviewinit() {         var loginproxy = $.proxy(this.attachsignin, this);         var redirecttopolls = $.proxy(this.redirecttopolls, this);         gapi.load('auth2', function () {             // retrieve singleton googleauth library , set client.             self.auth2 = gapi.auth2.init({                 client_id: '718161509287-jdpqsuebcoteh847krjn0m1odnbo5i3q.apps.googleusercontent.com',                 cookiepolicy: 'single_host_origin',                 // request scopes in addition 'profile' , 'email'                 //scope: 'additional_scope'             });             loginproxy(document.getelementbyid('custombtn'));         });      }       attachsignin = (element) => {          var navigate = false;         console.log(element.id);         self.auth2.attachclickhandler(element, {},             function (googleuser) {                  var profile = googleuser.getbasicprofile();                 console.log('id: ' + profile.getid()); // not send backend! use id token instead.                 console.log('name: ' + profile.getname());                 console.log('image url: ' + profile.getimageurl());                 console.log('email: ' + profile.getemail());                  //here want access router                 _router.navigate(['polls']);                    console.log(googleuser.getauthresponse().id_token);                }, function (error) {                 alert(json.stringify(error, undefined, 2));             });      }  } 

change function() () =>

    self.auth2.attachclickhandler(element, {},         (googleuser) => { 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -