Sushant Makin
Jan 13, 2022

--

Thanks, Don for reading through.

Directives like ngClass / ngStyle also use renderer2 behind the scene.

ngStyle: https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_style.ts#L77

ngClass: https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_class.ts#L153

So even though there is no security concern here but using the crude renderer2 API is much faster than using a directive like ngClass.

renderer2 changes the className property during the change detection cycle itself while the directive will not only generate more code but also handle all hooks (especially ngDoCheck hook) which will be an overhead to performance without any change in the end result.

Happy Coding!

--

--

Sushant Makin
Sushant Makin

Written by Sushant Makin

Software Architect at DAZN | Trying to make web development simpler & faster | Twitter: @sushantmakin

No responses yet