简体   繁体   English

Angular2页面已更新,但在IE中未更新

[英]Angular2 page updated, but not in IE

I play with an Angular2 app which fetches chat messages from a service. 我玩的是Angular2应用,该应用从服务中获取聊天消息。 Given a Pusher-notification, the app re-fetches all messages from the service. 给定Pusher通知,应用程序将从服务中重新获取所有消息。 This works well on all browsers, except IE. 这在除IE之外的所有浏览器上均能正常运行。 The push-notfication works ok, and the app logs that all messages are fetched correctly in IE also, but it seems that the browser does not re-render the updated content. 推送通知正常,并且该应用程序记录所有消息也已在IE中正确提取,但似乎浏览器未重新呈现更新的内容。 (IE 11). (IE 11)。 Any suggestions to why this is not happening? 有什么建议为什么不发生呢?

Component excerpt: 组件摘录:

    ngOnInit(){
        this.getMessages();
        this.pusher = new Pusher('PUSHER_KEY');
        this.channel = this.pusher.subscribe('test_channel');
        this.channel.bind('my_event', (data) =>{
                        this.getMessages();
            });
        console.log('In OnInit');
    }

    sendMessage(message:string): void{
        this._service.postMessage(this.id, message);
        console.log('Send Message called');
    }

    getMessages():void{
        this._service.getMessages(this.id)
            .subscribe(
                messages => this.messages = messages,
                error => this.errorMessage = <any>error);
    }

template: 模板:

<div class="panel-body">
        <div class="row">
            <div class="col-md-2">Add Message: </div>
            <div class="col-md-2"><input type="text" [(ngModel)]='newMessage'  /> <button class="btn btn-primary" (click)='sendMessage(newMessage)'>Send</button></div>
        </div>
        <div class="table-responsive">
            <table class="table" *ngIf='messages && messages.length'>
                <thead>
                    <tr>
                        <th>Messages</th>
                    </tr>
                </thead>
                <tbody>
                    <tr *ngFor='#message of messages'>
                        <td>{{message}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
</div>

Not sure if this helps but IMHO worth a try 不确定是否有帮助,但是恕我直言,值得一试

constructor(private zone:NgZone) {}

ngOnInit(){
    this.getMessages();
    this.pusher = new Pusher('PUSHER_KEY');
    this.channel = this.pusher.subscribe('test_channel');
    this.channel.bind('my_event', (data) =>{
        this.zone.run(() => this.getMessages());
    });
    console.log('In OnInit');
}

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

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