Follow the below steps:
1. Use 'ChangeDetectorRef' by importing it from @angular/core as follows:
import{ ChangeDetectorRef } from '@angular/core';
2. Implement it in constructor() as follows:
constructor( private cdRef : ChangeDetectorRef ) {}
3. Add the following method to your function which you are calling on an event like click of button. So it look like this:
functionName() {
yourCode;
//add this line to get rid of the error
this.cdRef.detectChanges();
}