Skip to content

Instantly share code, notes, and snippets.

@rhutchison
Last active September 1, 2015 03:20
Show Gist options
  • Save rhutchison/98bda7b51e9045e1cd08 to your computer and use it in GitHub Desktop.
Save rhutchison/98bda7b51e9045e1cd08 to your computer and use it in GitHub Desktop.
// Post repeat directive for logging the rendering time
angular.module('myApp').directive('postRepeatDirective',
['$timeout',
function($timeout) {
return function(scope, element, attrs) {
var timerName = attrs.postRepeatDirective || 'postRepeatDirective';
if (scope.$first) {
if (window.console && window.console.time) {
console.time(timerName);
} else {
window.a = new Date(); // window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
}
}
if (scope.$last) {
$timeout(function() {
if (window.console && window.console.time) {
console.time(timerName);
console.timeEnd(timerName);
} else if (window.console) {
console.log("## DOM(" + timerName + ") rendering list took: " + (new Date() - window.a) + " ms");
}
});
}
};
}
]);
// Use in HTML:
<tr ng-repeat="item in items" post-repeat-directive>…</tr>
OR
<tr ng-repeat="item in items" post-repeat-directive="itemList">…</tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment