当我收到套接字事件时,我只是想更新我的视图.我在组件中的代码如下所示:
constructor(private _zone: NgZone){
this.socket = io.connect('http://localhost:3000');
this.socket.on('someEvent', function(data) {
this._zone.run(() => {
this.dataItem = data.item;
console.log(this.dataItem);
});
});
}
Run Code Online (Sandbox Code Playgroud)
当我运行此浏览器控制台时显示一些错误:
EXCEPTION: TypeError: Cannot read property 'run' of undefined
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我的socket事件在index.html中正常工作
任何形式的帮助表示赞赏.
android ×1
angular ×1
angularjs ×1
google-maps ×1
socket.io ×1
typescript ×1
utility ×1
websocket ×1