簡體   English   中英

Angular2 OnInit不會觸發IE11

[英]Angular2 OnInit Not Firing IE11

當您導航到另一個angular2路線時,IE11似乎沒有觸發OnInit,然后返回到原始路線。 所以要清楚route1是有問題的路由,是默認路由。 當route1加載OnInit在我的component1中觸發就好了,我導航到route2 / component2 OnInit也很好。 問題是當我導航回route1 / component1時,OnInit不會在IE中觸發,但在所有其他瀏覽器中都會觸發。 我們在RC3上。

這是我的組件:

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);
    }
}

謝謝!

編輯1 ---我注意到當DOM中發生其他事件時(即onhover在元素上觸發,或者我打開下拉列表,OnInit方法觸發,似乎當angular2更改檢測觸發它最終觸發OnInit時)

編輯2 ---問題仍然存在於rc4中。 好像我的問題是:

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

鏈接到修復程序顯示對router.ts的更新。 我沒有看到捆綁在npm包中的文件,只有轉換后的router.js文件。 我如何應用此更新?

謝謝

似乎有幾個關於Angular2 github網站上的重復問題的報告。 我從這個鏈接解決了一個問題GitHub問題

我必須做的唯一修改是_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);
    });

}

我希望在RC5中解決這個問題,但這似乎現在有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM