Angular Google Auth2

时间:2017-10-13 11:51:23

标签: angular google-oauth


抱歉愚蠢的问题,但我是Angular的新人 当我登录时:按钮从登录更改为注销,但随后我刷新页面全部返回

这是我的模板:

<div class="col-xs-4 col-sm-8 top-panel-right">
<ul class="nav navbar-nav pull-right panel-menu">
  <li *ngIf="(isSignedIn | async) == false">
     <button class="btn-link" (click)="googleAuthObject.signIn()">
        Login
     </button>
  </li>
  <li  *ngIf="isSignedIn| async">
    <button class="btn-link" (click)="googleAuthObject.signOut()">
       Logout
    </button>
  </li>



这是我的组成部分:

public googleAuthObject;

public isSignedIn: Observable<boolean>;

constructor (private googleAuth: GoogleOauth) {
    let that = this;
    this.googleAuth.getOauth((googleAuth)  => {
        that.googleAuthObject = googleAuth;
        googleAuth.isSignedIn.listen(that.signInCheking);
        that.signInCheking(googleAuth.isSignedIn.get());
    });
}

public signInCheking(isSignedIn: boolean) {
    if (isSignedIn) {
        console.log(isSignedIn);
        this.isSignedIn = Observable.of(isSignedIn);
    }
}


googleAuth.isSignedIn.get();

返回true,但isSignedIn和模板不更新
这是我的google-client-wrapper:

private scope = [
    'profile',
].join(' ');

public getOauth(callback){
    let that = this;
    gapi.load('auth2', function () {
        gapi.auth2.init({
            client_id: that.clientId,
            cookiepolicy: 'single_host_origin',
            scope: that.scope
        }).then(callback)

    });
}

0 个答案:

没有答案