我要做的就是在从网络套接字收到消息时更改HTML中的值。 这是Angular脚本:
var dashboard = angular.module("dashboardApp", ['ngWebSocket']);
dashboard.controller("dashboardController", ["$scope", "$http", function ($scope, $http, $websocket) {
$scope.BTC_price = 0;
var ws = new WebSocket('ws://127.0.0.1:3000/');
var collection = [];
ws.onopen = function () {
console.log('websocket is connected ...')
//ws.send('connected')
}
// event emmited when receiving message
ws.onmessage = function (ev) {
console.log(ev.data);
$scope.BTC_price = 100;
}
该值已在回调onmessage
中正确接收,我可以在控制台日志中看到它。但是$scope.BTC_price
不会在HTML中更新。
我看错了$ scope吗?