我收到错误
Property 'duni' has no initializer and is not definitely assigned in the constructor.ts(2564)
Run Code Online (Sandbox Code Playgroud)
在下面一行
@ViewChild('bhondu') duni: ElementRef<HTMLTableDataCellElement>;
Run Code Online (Sandbox Code Playgroud)
在我使用给定的?其他地方使用打破代码使其成为可选。如何在不更改配置文件中的任何属性的情况下解决此错误?this.duni.nativeElementObject is possibly 'undefined'.ts(2532)
在我的 Angular 打字稿文件中,我有以下代码。我需要帮助来解决这个打字稿错误
ngAfterViewInit() {
setTimeout(() => {
this.tada = document.querySelectorAll('.highlighted').length;
document.querySelector<HTMLElement>('.highlighted')?.style.backgroundColor = 'pink';->>Error
this.fckme();
}, 50);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
Run Code Online (Sandbox Code Playgroud)
我创建了自定义管道,如果我循环遍历文本并搜索单词,如果给定文本中存在单词,我会向其中添加突出显示的类,以便我可以用粉红色突出显示该单词
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;
}
}
Run Code Online (Sandbox Code Playgroud)