Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs ng-repeat adding html comments on dom

Why does angularjs cause multiple comments in between render data? Inspecting DOM childNodes causes extra nodes which takes up memory. Is there a way to remove them?

enter image description here

like image 680
Claude Avatar asked Nov 07 '14 20:11

Claude


3 Answers

Angular needs these comments to operate with some directives. Removing those comments breaks Angular and it is not allowed to do so currently.

It is also explained in this Github issue.

like image 77
halilb Avatar answered Sep 18 '22 13:09

halilb


Angular uses the comments do figure out where the last element was placed in relation. It's here in the source code https://github.com/angular/angular.js/commit/9efa46ae640cde17487c341daa9a75c0bd79da02

The comments are written client-side so there's no impact on transfer, and if your application is that memory conservative, Angular is probably the wrong language to use in the first place.

like image 24
Stephen Punwasi Avatar answered Sep 18 '22 13:09

Stephen Punwasi


I find these comments annoying too. You can turn off the content of them though. Just set debugInfoEnabled to false in the config:

$compileProvider.debugInfoEnabled(false);
like image 41
david.carm Avatar answered Sep 20 '22 13:09

david.carm