In my Angular typescript file I have following code. I need help to solve this typescript error
ngAfterViewInit() {
setTimeout(() => {
this.tada = document.querySelectorAll('.highlighted').length;
document.querySelector<HTMLElement>('.highlighted')?.style.backgroundColor = 'pink';->>Error
this.fckme();
}, 50);
}
I am getting the following error
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
I have created custom pipe where if I get loop through text and search for a word, if word is present in given text I add highlighted class to it so that, I can hilight that word with pink color
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'highlight'
})
export class HiPipe implements PipeTransform {
transform(v1: string, v2: string): unknown {
//some code
for (const match of matches) {
value = value.replaceAll(match, `<span class = "highlighted data-${match}">${match}</span>`);
}
return v1;
}
}