每当我从websocket收到消息时,我都想更改正文的html。这是我的HTML代码
<table class="table table-hover" ng-controller="userController">
<thead class="text-white text-uppercase">
<tr>
<th>
<i class="fa fa-star"></i>
Favourites
</th>
<th>
Coin
</th>
<th class="colorBlue">
<i class="la la-arrow-up"></i>
Price
</th>
<th>
24h change
</th>
<th>
Market cap
</th>
<th>
24h vol
</th>
<th>
<div class="m-input-icon m-input-icon--right">
<input type="text" class="form-control m-input m-input--square" placeholder="Search">
<span class="m-input-icon__icon m-input-icon__icon--right">
<span>
<i class="fa fa-search"></i>
</span>
</span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="firstTd">
<i class="fa fa-star"></i>
<span class="bitcoinBigIcon"></span>
</td>
<td>
<div class="iconAndTitle text-white">
<span class="colorBlue text-uppercase">Btc</span>
<div class="clearfix"></div>
Bitcoin
</div>
</td>
<td class="text-white" ng-bind-html="myD">
$123456
</td>
<td class="colorGreen">
<i class="fa fa-caret-up"></i>
1.90%
</td>
<td class="text-white">
$110,769.74M
</td>
<td class="text-white">
$1,505.98M
</td>
<td class="text-right">
<i class="colorDanger la la-times-circle-o"></i>
</td>
</tr>
</tbody>
</table>
还有我的Angular JS代码。
angular.module('myApp', [
'ngWebSocket' // you may also use 'angular-websocket' if you prefer
])
//WebSocket works as well
.factory('MyData', function($websocket) {
// Open a WebSocket connection
var dataStream = $websocket('wss://stream.binance.com:9443/ws/!ticker@arr');
var collection = [];
dataStream.onMessage(function(message) {
collection.push(JSON.parse(message.data));
});
var methods = {
collection: collection,
get: function() {
dataStream.send(JSON.stringify({ action: 'get' }));
}
};
return methods;
})
.controller('userController', function ($scope, MyData) {
$scope.MyData = MyData;
});
每当我收到一些消息时,我都想进行一些计算和处理。我对angular js相当陌生,所以我想知道它是如何工作的?什么
.controller('userController', function ($scope, MyData) {
$scope.MyData = MyData;
});
这行吗?我将在哪里进行所有计算和处理?就像假设我将这些ID赋予TR
,并且想要对其进行操作,只需更改TD
s的内部值,我该怎么办?