I know there are some similar questions but none answer my question.
Basically what is the correct way to manipulate the DOM in angular say I have this.
html
<button id="buy-now">BUY NOW</button>
and when you click the button I want the button to turn purple so in pure javascript you would write something like
javascript
changeColour() {
const b = document.getElementById('buy-now');
b.style.backgroundColor = 'purple';
}
now In Angular I have been doing it this way, but recently noticed people saying this is not correct??
What is the correct way to manipulate the DOM in angular, and how would I rewrite my example to reflect this corrected way??
Any help would be appreciated!
EDIT
To be clear, I know in Angular I can do this
HTML
<button (click)="changeColour()" id="buy-now">BUY NOW</button>
TS FILE
changeColour() {
const b = <HTMLElement>document.querySelector('#buy-now');
b.style.backgroundColour = 'purple'
}
but is this the appropriate way to manipulate the dom??
Changing the button colour was only a quick example, I mean for any type of DOM Manipulation
Thanks