Working with DOM in Angular: unexpected consequences and optimization techniques