What I did with Knockout, and I'm trying to do with Angular.
In my current project, I have a table whose data is added by a scroll event. When the user scrolls down, I add 20 rows to the end of the table, and the total number of rows can reach 2 to 10 thousand. I start showing 20 records, and when the user scrolls down, I continue to add 20 rows until the total number of rows is reached.
As in the Angular script example, when replay is used, if new data is placed in the Angular array, all records are executed and rendered again, but the knockout only executes and displays the new record added. In my project, because I show thousands of data in one table in a way that Angular works, or I think it works, kills my performance.
Only a few weeks have passed when I use Angular. I dont know. If I do something wrong or I need to change some things.
Knockoutjs example :
<h2>Your seat reservations</h2> <table> <thead><tr> <th>Passenger name</th><th>Meal</th><th>Test</th> </tr></thead> <tbody data-bind="foreach: seats()"> <tr> <td data-bind="text: mealName"></td> <td data-bind="text: price"></td> <td data-bind="text: $root.cellAdded()"></td> </tr> </tbody> </table> <button data-bind="click: $root.PushData()">I am Here</button>
JS:
// Overall viewmodel for this screen, along with initial state function ReservationsViewModel() { var self = this; self.cellAdded = function(){ console.log('Test Added'); return 'ok'; }; self.PushData = function(){ console.log('PushData Called'); self.seats.push({ mealName: "Standard (sandwich)", price: 0 }); }; // Editable data self.seats = ko.observableArray([ { mealName: "Standard (sandwich)", price: 0 }, { mealName: "Premium (lobster)", price: 34.95 }, { mealName: "Ultimate (whole zebra)", price: 290 } ]); } ko.applyBindings(new ReservationsViewModel());
AngularJS example :
<div ng-app> <div ng-controller="TodoCtrl"> <h2>Your seat reservations</h2> <table> <thead><tr> <th>Passenger name</th><th>Meal</th><th>Test</th> </tr></thead> <tbody > <tr ng-repeat="seat in seats"> <td>{{seat.mealName}}</td> <td>{{seat.price}}</td> <td>{{callMe()}}</td> </tr> </tbody> </table> <button ng-click="addRow()">Add Row</button> </div> </div>
JS:
function TodoCtrl($scope) { $scope.callMe = function(){ console.log('Test Added'); return 'Yes'; }; // initialize controller model $scope.seats = [ { mealName: "Standard (sandwich)", price: 0 }, { mealName: "Premium (lobster)", price: 34.95 }, { mealName: "Ultimate (whole zebra)", price: 290 } ]; // Define member functions $scope.addRow = function() { console.log('PushData Called'); $scope.seats.push( { mealName: "Standard (sandwich)", price: 0 }); }; }