I am experimenting with building a real-time stock ticker app using angularjs.
app.js
var sa = angular.module('sa', []);
sa.controller('HomeController', function ($scope, $http, $timeout) {
var poll = function() {
$http.get('/api/v1/stocks').success(
function(stocks)
{
$scope.stocks = stocks;
$timeout(poll, 2000);
}
);
};
poll();
});
home.html
<table>
<tbody>
<tr data-ng-repeat="stock in stocks">
<td>{{ stock.code }}</td>
<td>{{ stock.bid }}</td>
<td>{{ stock.ask }}</td>
</tr>
</tbody>
</table>
The poll works fine and updates stocks correctly, however what I am looking to achieve is if the stock value increases, then animate-flash the background of that bid/ask in green. If the stock value decreases, then animate-flash the background of that bid/ask in red.
What I am looking for is for background of stock to flash red / green, then fade out to background colour.
Is there a watch / event listener function that can help me tap into this?
items by just changing the td to ul?
– rex Apr 30 '14 at 21:32items not in an an ng-repeat. Any chance you can give an example of how its done? Having trouble adapting this code to do it :(
– rex Apr 30 '14 at 21:39item that is just in a div (no ng-repeat)
– rex Apr 30 '14 at 21:53