如何将数据发送回页面

时间:2017-11-29 15:41:22

标签: angular ionic3 server-sent-events

我目前正在开发一个POC离子应用程序,用于从SSE Rest API流式传输数据。

我有一个页面来显示调用提供程序的数据,并将其传递给设备名称以进行读取。 我在SSE流的控制台中有数据但是我无法弄清楚如何将这些数据发送回欢迎页面以显示给用户。

scanForData(mac, token) {
// Open a connection
let stream = new EventSource(apiURL + 'gap/nodes?event=1&mac=' + mac + '&access_token=' + token);

// When a connection is made
stream.onopen = function() {
  console.log('Opened connection ');
};

// A connection could not be made
stream.onerror = function (event) {
  console.log(event);
};

// When data is received
stream.onmessage = function (event) {
  console.log(event.data);
  this.WelcomePage.newData(); //this doesn't work (Undefined)
};

// A connection was closed
stream.onclose = function(code, reason) {
  console.log(code, reason);
}

// Close the connection when the window is closed
window.addEventListener('beforeunload', function() {
  stream.close();
});

}

我正在学习Angular / Ionic,但是我会感激任何帮助。

0 个答案:

没有答案