To access your DOM elements, you can utilize the ViewChild decorator like this:
@Component({
....
templateUrl: 'mytemplate.html'
})
export class MyComponent{
@ViewChild('selector') private someName;
constructor() {
//this gives you access to your DOM element
//this.someName.nativeElement
}
}
In your template class, make sure to specify the selector:
<div #selector> </div>
Alternatively, you can also use the ElementRef class:
import {Component, AfterViewInit, ElementRef} from "@angular/core";
export class MyComponent implements AfterViewInit {
constructor(protected elementRef: ElementRef) {
}
ngAfterViewInit() {
//you can access your DOM element using
//this.elementRef.nativeElement
}
}
You have the flexibility to incorporate third-party libraries like jQuery for functionalities such as addClass and removeClass within typescript.