简体   繁体   English

Angular2 OnInit不会触发IE11

[英]Angular2 OnInit Not Firing IE11

It seems like IE11 isn't firing OnInit when you navigate to another angular2 route, then come back to the original route. 当您导航到另一个angular2路线时,IE11似乎没有触发OnInit,然后返回到原始路线。 So to be clear route1 is the route in question and is the default route. 所以要清楚route1是有问题的路由,是默认路由。 When route1 loads OnInit is fired in my component1 just fine, I navigate to route2/component2 OnInit fires fine as well. 当route1加载OnInit在我的component1中触发就好了,我导航到route2 / component2 OnInit也很好。 The issue is when I navigate back to route1/component1 OnInit doesn't fire in IE, but it does in all other browsers. 问题是当我导航回route1 / component1时,OnInit不会在IE中触发,但在所有其他浏览器中都会触发。 We're on RC3. 我们在RC3上。

Here is my component in question: 这是我的组件:

import { Component, OnInit} from '@angular/core';
import { UdrService} from './udr.service';
import { Widget} from '../widget';

@Component({
    selector: 'udr',
    templateUrl: './Home/RenderUDR',
    providers: [UdrService]
})

export class UdrComponent implements OnInit {
    constructor(private _udrService: UdrService) { }

    widgets: Widget[];

    ngOnInit() {
        this._udrService.getUdrActiveWidgets()
            .subscribe(wdgts => this.widgets = wdgts);
    }
}

Thanks! 谢谢!

EDIT 1 --- I have noticed that when other events happen in the DOM (ie onhover is fired on an element, or i open a drop down, the OnInit method fires, it seems like when angular2 change detection fires it finally fires OnInit) 编辑1 ---我注意到当DOM中发生其他事件时(即onhover在元素上触发,或者我打开下拉列表,OnInit方法触发,似乎当angular2更改检测触发它最终触发OnInit时)

EDIT 2 --- The issue is still present in rc4. 编辑2 ---问题仍然存在于rc4中。 It seems like my issue is this: 好像我的问题是:

https://github.com/angular/angular/issues/10146 https://github.com/angular/angular/issues/10146

The linked to fix shows an update to router.ts. 链接到修复程序显示对router.ts的更新。 I dont see that file bundled in the npm package, only the transpiled router.js file. 我没有看到捆绑在npm包中的文件,只有转换后的router.js文件。 How do i apply this update? 我如何应用此更新?

Thanks 谢谢

It seems like there are several reports of this issue that are duplicates on the Angular2 github site. 似乎有几个关于Angular2 github网站上的重复问题的报告。 I lifted a work around from this link: GitHub Issue 我从这个链接解决了一个问题GitHub问题

The only modification I had to make was _router.events.subscribe instead of _router.subscribe because I think _router.events.subscribe is new to the component router. 我必须做的唯一修改是_router.events.subscribe而不是_router.subscribe,因为我认为_router.events.subscribe对组件路由器来说是新的。

export class AppComponent {

constructor(private _applicationRef: ApplicationRef, private _router: Router) {

    _router.events.subscribe(() => {
        this._applicationRef.tick();
        setTimeout(() => {
            this._applicationRef.tick();
        }, 100);
    });

}

I hope this is resolved in RC5, but this seems to work for now. 我希望在RC5中解决这个问题,但这似乎现在有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM