Angular2 Safari Back Button

六月ゝ 毕业季﹏ 提交于 2019-12-05 08:16:37
Gary Batterbee

On "angular2": "2.0.0-beta.14"

I had to run the tick inside a zone to get it to work for me.

import {ApplicationRef, <anything else you need>} from 'angular2/core';
import {Router,<anything else you need>} from 'angular2/router';

export class AppComponent {
    constructor(private _ref: ApplicationRef, private _router: Router) {
        _router.subscribe((value) => {
            _ref.zone.run(() => _ref.tick());
        });
    }
}
kemsky

There is partial workaround for this bug:

  1. Inject Router and ApplicationRef into Application component
  2. Subscribe for router changes and trigger full component tree check:
    router.subscribe((value)=>
    {
        //todo: check browser UA or any other parameters to detect back button, i.e. if (safari) {}

        //trigger change that will invoke init methods
        appRef.tick();
    });

angular2 - 2.15.8

constructor(private _ref: ApplicationRef, private _router: Router) {
        _router.events.subscribe((value) => {
            _ref.zone.run(() => _ref.tick());
        });
    }

Using _router.subscribe is deprecated and will throw Undefined function .subscribe() on _router.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!