【问题标题】:Angular2 Router - window.opener: Lost Change Detection at forwarAngular2路由器-window.opener:前向丢失更改检测
【发布时间】:2017-04-11 16:39:08
【问题描述】:

当我打开 OAuth 的弹出窗口并通过

返回时
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']);
    }
}

这是一个错误,还是我做错了什么?

【问题讨论】:

    标签: javascript angular angular2-routing prototype-programming


    【解决方案1】:

    好的,谷歌搜索了一个解决方案:只需要使用 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']);
            });
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-01
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 2022-11-10
      • 2016-10-27
      • 2017-10-03
      • 2017-06-27
      • 1970-01-01
      相关资源
      最近更新 更多