我使用Angular2应用程序从服务中获取聊天消息。给定Pusher通知后,应用程序将重新提取服务中的所有消息。这适用于所有浏览器,IE除外。推送通知工作正常,应用程序记录所有消息也在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>
答案 0 :(得分:0)
不确定这是否有帮助但IMHO值得一试
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');
}