【发布时间】:2021-05-07 06:54:53
【问题描述】:
在我的 Angular 打字稿文件中,我有以下代码。我需要帮助来解决这个打字稿错误
ngAfterViewInit() {
setTimeout(() => {
this.tada = document.querySelectorAll('.highlighted').length;
document.querySelector<HTMLElement>('.highlighted')?.style.backgroundColor = 'pink';->>Error
this.fckme();
}, 50);
}
我收到以下错误
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
我创建了自定义管道,如果我在文本中循环并搜索单词,如果给定文本中存在单词,我会向它添加突出显示的类,以便我可以用粉红色突出显示该单词
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;
}
}
【问题讨论】:
标签: angular typescript runtime-error