[英]AngularJS refresh doesn't seem to work
我有一個簡單的2個部分,我想成為新老成員。 一旦完成new並調用套接字,則old = new,而new應該為空。 關鍵是,一切仍會添加到上部(新)部分。 最后一個套接字負責管理此操作。
控制器:
.controller('DepositsCtrl', function ($scope, mySocket) {
$scope.deposits = [];
$scope.olddeposits = [];
$scope.winnerSteamName = "";
$scope.roundValue = 0;
$scope.winnerChance = 0;
$scope.avatarWinner = "";
mySocket.on('sendDepositIO', function(steamIdIO, itemCountIO, depositValueIO, avatarIO, steamNameIO) {
$scope.deposits.push({
steamId: steamIdIO,
itemCount: itemCountIO,
depositValue: depositValueIO,
avatar: avatarIO,
steamName: steamNameIO
})
});
mySocket.on('newConnection', function (depositsInRound, olddepositsInRound) {
$scope.deposits = depositsInRound;
$scope.olddeposits = olddepositsInRound;
});
mySocket.on('newRoundDeposit', function () {
$scope.olddeposits = $scope.deposits;
$scope.deposits = [];
});
HTML:
<div ng-controller="DepositsCtrl">
<h2>Deposits</h2>
<hr class="line-under">
<section class="round section">
<ul>
<li class="li-deposit" ng-repeat="deposit in deposits | orderBy:'-'">
<div class="deposit-person"><img class="small-avatar" ng-src="{{deposit.avatar}}" /> <span class="name">{{deposit.steamName}}</span> </div>
<div class="deposit-items">{{deposit.itemCount}} items</div>
<div class="deposit-value">{{deposit.depositValue}}$</div>
</li>
<li>
<hr class="line-under">
<h3 class="new-round text-center">New Round <i class="fa fa-arrow-up fa-lg"></i></h3>
</li>
</ul>
</section>
<section class="round section">
<ul>
<li>
<div class="text-center center-block">
<img class="small-avatar" ng-src="{{avatarWinner}}" /><span>{{winnerSteamName}} has won {{roundValue}} with {{winnerChance}}% chance !</span>
</div>
</li>
<li class="li-deposit" ng-repeat="olddeposit in olddeposits | orderBy:'-'">
<div class="deposit-person"><img class="small-avatar" ng-src="{{olddeposit.avatar}}" /> <span class="name">{{olddeposit.steamName}}</span> </div>
<div class="deposit-items">{{olddeposit.itemCount}} items</div>
<div class="deposit-value">{{olddeposit.depositValue}}$</div>
</li>
<li>
<hr class="line-under">
<h3 class="new-round text-center">Previous Round <i class="fa fa-arrow-up fa-lg"></i></h3>
</li>
</ul>
</section>
</div>
看完您的代碼並閱讀了與Leandro的討論后,我想知道。
您真的確定發出並捕獲了“ newRoundDeposit”嗎?
抱歉,這是一個愚蠢的問題,但是對我來說,您的編碼看起來正確。
數組是對象,對象是通過引用分配的,因此當您執行$ scope.olddeposits = $ scope.deposits時,會將存儲在存儲中的引用分配給olddeposits。
嘗試$scope.olddeposits = angular.copy($scope.deposits);
看看會發生什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.