如何获得可观察到的更新IE中的变量? [英] How do I get an observable to update a variable in IE?

查看:119
本文介绍了如何获得可观察到的更新IE中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我可以使此代码在Chrome中运行,但找不到适用于Safari和IE的解决方案.我还没有尝试过Firefox.我的项目正在使用打字稿转译器.

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

柱塞示例

推荐答案

您的代码可在Firefox中使用,但不能在Safari和IE中使用,这看起来很奇怪.我的猜测是zone.js对此负责.更改了示例以通过区域调用更新:

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

现在它可以在Safari中使用 plunkr

now it works in Safari plunkr

这篇关于如何获得可观察到的更新IE中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆