this.zone.run() - Ngzone错误

时间:2017-08-26 06:37:11

标签: angularjs node.js sockets sails.js

我遇到风帆+风帆插座+ 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:无法读取属性'运行'未定义的

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

0 个答案:

没有答案