I want to update the value of a property in a push action, but I do not know how to access a property from a function!
export class Datas { prop1 = "my val"; } var connection = new WebSocket('ws://localhost:8787', 'json'); connection.onmessage = function (e) {
Any ideas?
Edit: After loading the page, I want to update the data when I receive a push message.
Edit 2: test 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 the message: Data.information = 4"
"data status. information: 4"
"state of this information: undefined"
source share