我的组件中有一个角度组件,我需要访问element的内部html。为此,我可以将ViewChild与模板ref一起用于单个元素。但是在ngFor中,当我动态生成元素和模板ref时,它不起作用。这是控制台中显示的错误:-
Cannot read property 'native Element' of undefined
Run Code Online (Sandbox Code Playgroud)
这是单个元素的代码:-
@ViewChild('emailBodyContainer') emailBodyContainer: ElementRef;
<div [innerHtml]="emailTemplate.mailBody" #emailBodyContainer>
Run Code Online (Sandbox Code Playgroud)
对于动态元素:-
<div *ngFor="let i of reminderTemplates" class="container tab-pane text-center py-4 [innerHtml]="i.mailBody" #{{i.type}}></div>
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题。提前致谢 :)