How do I get an observable to update a variable in IE?

醉酒当歌 提交于 2019-12-12 03:37:46

问题


For some reason I can get this code to work in Chrome but did not find a solution for Safari and IE. I haven't tried Firefox yet. My project is using the typescript transpiler.

constructor(){
    this.eventStream = Observable.fromEvent(window,'resize');
    this.eventStream.subscribe((event) => this.updateWindow(event));
}

ngOnInit(){
    this.updateWindow();
}

updateWindow(event:any){
    this.updateHeight = window.innerHeight;
}

Plunker example


回答1:


Your code works in Firefox, but not in Safari and IE, it looks strange. My guess is that zone.js is responsible for that. Changed your example to invoke update through zone:

constructor(zone:NgZone)
{
this.eventStream = Observable.fromEvent(window,'resize');
this.eventStream.subscribe((event) => {zone.run(()=> {this.updateWindow(event)}) });
}

now it works in Safari plunkr



来源:https://stackoverflow.com/questions/36756196/how-do-i-get-an-observable-to-update-a-variable-in-ie

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