I want to refresh a property's value on push action, but i don't know how to access to the property from a function !
export class Datas {
prop1 = "my val";
}
var connection = new WebSocket('ws://localhost:8787', 'json');
connection.onmessage = function (e) {
// prop1 of Datas = e.data;
};
Any ideas ?
Edit : After the page loads, I want to refresh the data when receiving a push message.
Edit 2 : testing code
data.js :
export class Data {
static information = '';
}
viewModel.js
import {bindable} from 'aurelia-framework';
import { Data } from 'data';
export class ViewModel {
constructor() {
this.informaton = Data.information;
}
logState(){
console.log("state of Data.information : " + Data.information);
console.log("state of this.information : " + this.information);
}
}
var connection = new WebSocket('ws://localhost:8787', 'json');
connection.onmessage = function (e) {
Data.information = e.data;
console.log("receiving a message : Data.information = " + Data.information);
};
viewModel.html:
<template>
<span id="spanAff">${information}</span>
<br/>
<input type="button" value="log" click.trigger="logState()" />
</template>
logs :
"receiving a message : Data.information = 4"
"state of Data.information : 4"
"state of this.information : undefined"
I got this solution on another forum :
export class ViewModel {
constructor() {
this.information = 'my val';
var connection = new WebSocket('ws://localhost:8787', 'json');
connection.onmessage = e => {
this.information = e.data;
};
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With