MD10
MD10

Reputation: 1521

Expression has changed after it was checked-using @ViewChild reference

Hi I am using this context menu component: https://www.npmjs.com/package/ngx-contextmenu when I am binding the [contextMenu]="basicMenu" like this, and using the basicMenu with

@ViewChild(ContextMenuComponent)
public basicMenu:ContextMenuComponent

I get the following error: ExpressionChangedAfterItHasCheckedError: Previous Value: 'contextMenu:undefined'.Current value:'contextMenu[object Object]'

I know that the error is cause becuase the value is changed before the view is initialized in the middle of the process that runs the hooks.So I tried to run the change detection in the ngAfterViewInit with changeDetectorRef, however it doesnt work either...

Upvotes: 2

Views: 1056

Answers (1)

AliF50
AliF50

Reputation: 18839

Try:

@ViewChild(ContextMenuComponent, { static: true }) public basicMenu: ContextMenuComponent;

I think there were some breaking changes with @ViewChild in Angular 9.

Upvotes: 2

Related Questions