How to use ElementRef security risk free in Angular 8?

I am confused about ElementRef using in Angular 8. I read that permitting direct access to the DOM can make your application more vulnerable to XSS attacks. I am scared about it. Experts, please guide me. My code is mentioned below:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

then

@ViewChild("elem", { static: false }) elem: ElementRef;

and use it as:

this.elem.nativeElement.classList.add('current');

Another, page I use the following code:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
constructor(private elRef: ElementRef){}

and use as:

let elements = this.elRef.nativeElement.querySelectorAll(".roundIcon");
console.log(elements);

Please guide that two methods are XSS attacks safe?
Thanks in advance.

Source: New feed
Source Url How to use ElementRef security risk free in Angular 8?