【问题标题】:Angular2 page updated, but not in IEAngular2 页面已更新,但在 IE 中没有
【发布时间】:2016-08-05 17:35:00
【问题描述】:

我使用 Angular2 应用程序从服务中获取聊天消息。给定一个 Pusher 通知,应用程序从服务中重新获取所有消息。这适用于所有浏览器,除了 IE。推送通知工作正常,并且应用程序记录所有消息在 IE 中也正确获取,但似乎浏览器不会重新呈现更新的内容。 (即 11)。关于为什么没有发生这种情况的任何建议?

组件摘录:

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

模板:

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

【问题讨论】:

    标签: internet-explorer angular pusher


    【解决方案1】:

    不确定这是否有帮助,但恕我直言,值得一试

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

    【讨论】:

    • 不幸的是,使用 this.zone 并没有对 IE 行为产生任何影响。
    • 我想这需要一个 Plunker 来重现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2019-03-26
    • 1970-01-01
    相关资源
    最近更新 更多