after my angular application versions upgrade from angular 7 to angular 8 i run into a complication problem with rows like this
export class followupComponent implements OnInit {
@ViewChild('message') messageElement: ElementRef;
constructor(){}
...
}
I read that the new definition required static
parameter
and change the code
@ViewChild('message', { static: true })) messageElement: ElementRef;
and I thought that the problem had resolved.
But no, i accept run time error:
cannot read property 'nativeElement' of undefined
related to this code
HTML:
<div class="message">
<div class="action-buttons">
<img src="{{imgPath + '_Edit_Hover.png'}}" (click)="OnEdit(Followup)">
</div>
<textarea matInput #message [ngModel]="Followup.Message"></textarea>
</div>
TS:
OnEdit(followup: Followup) {
setTimeout(() => this.messageElement.nativeElement.focus());
}
What is the correct definition of ElementRef
in angular 8,
or - How to resolve this problem?