0

當我打開OAuth的一個彈出窗口,並通過Angular2路由器 - window.opener:失落的變化檢測在forwar

window.opener.closeCallbackFunction(); 

然後我ChangeDetection不再被轉發的網頁上正常返回。

function _window(): any { 
    return window; 
} 

@Component({ 
    selector: 'app-register', 
    templateUrl: './register.component.html', 
}) 
export class ConsultantRegisterComponent { 

    constructor() { 
    } 

    openPopup() { 
     let _this = this; 
     let selfWindow = _window(); 
     let popup = lib.PopupCenter('/RegisterWithFacebook', 'Sign In', 600, 400); 

     selfWindow.closeCallbackFunction = function() { 
      popup.close(); 
      _this.forward.call(_this); 
     }; 

    } 

    forward() { 
     this.router.navigate(['/register-oauth']); 
    } 
} 

這是一個錯誤,還是我做錯了什麼?

回答

0

好,用Google搜索的解決方案:只需要與NgZone做到這一點:

function _window(): any { 
    return window; 
} 

@Component({ 
    selector: 'app-register', 
    templateUrl: './register.component.html', 
}) 
export class ConsultantRegisterComponent { 

    constructor(private _zone:NgZone) { 
    } 

    openPopup() { 
     let _this = this; 
     let selfWindow = _window(); 
     let popup = lib.PopupCenter('/RegisterWithFacebook', 'Sign In', 600, 400); 

     selfWindow.closeCallbackFunction = function() { 
      popup.close(); 
      _this.forward.call(_this); 
     }; 

    } 

    forward() { 
     this._zone.run(() => { 
      this.router.navigate(['/register-oauth']); 
     }); 
    } 
}