this.zone.run() – Nzone的错误

我有一个问题,帆+帆sockets + angular4

import { Component, OnInit, NgZone } from '@angular/core'; import { routerTransition } from '../../router.animations'; import { Http } from '@angular/http'; import * as socketIOClient from 'socket.io-client'; import * as sailsIOClient from 'sails.io.js'; @Component({ selector: 'app-tables', templateUrl: './tables.component.html', styleUrls: ['./tables.component.scss'], animations: [routerTransition()] }) export class TablesComponent implements OnInit { io:any; smartTableData:any; constructor(public http: Http, private zone: NgZone) { this.io = sailsIOClient(socketIOClient); this.io.sails.url = "http://localhost:1337"; this.io.socket.get('/posts', function(resData, jwr) { console.log (resData); return resData; }); this.io.socket.on('updateposts', function(data) { this.zone.run(() => { this.smartTableData = data; }); }); } ngOnInit() { } } 

套接字广播数据时。 行this.socket.on(“updataposts”)运行,但ngZone不起作用。

zone.js:196 Uncaught TypeError:无法读取未定义的属性'run'

我想更新数据来查看接收套接字数据时。 请帮帮我! 谢谢!