Set values that are changing all the second

Hi, I’m trying to print on my page two datas from a buffer, the two variables are actualised all the second.

To get the datas I use :

liveData() {
	   var that = this;
	   setInterval(function() {
	       BluetoothSerial.isConnected().then(()=> {
				BluetoothSerial.read().then((data) => {
					console.log(data);
					this.tabLive = data.split('\n');
					var line = this.tabLive[0].split(",");
					console.log("line");
					console.log(line);
					this.tempLive = parseInt(line[4]);
					this.turbidityLive = parseInt(line[3]);
					console.log("tempLive"+this.tempLive);
					console.log("turbidityLive"+this.turbidityLive);
				});
			});
	   }, 1100);
	}

I call this function in the constructor, and I use :

<input [(value)]="tempLive" >
<input [(value)]="turbidityLive" >

in order to print the data in my page, but I just have undefined printed …
Do you have an idea why ?

function () {
  this.tempLive =   // this here is NOT the component
}

use arrow functions instead

() => {
  this.templateLive = // this is the component, so you'll be binding the property to the right object
}

so replace any function () with () =>

Thank you, now I have the data display in the html but they are not updated.
Is there something to do in order to update the html for each change of the data ?

This looks like a perfect candidate for using an Observable.

2 Likes

Can you post the updated code? whole file no exclusion.