I know why i am getting the Expression Changed After it has been checked error but i cannot prevent it .
Scenario
I have a Component that has a ngxDatatable we manipulate the Datatable to take up width of a div based on certain condition what happens is that the re rendering of the data grid dosent happen for some odd reason as it happens in the same Event loop. So what we end up doing is that when ever we get a resize event from our datagrid component we capture that in a custom directive and emit a event that will then call the datatable recalulate event . This makes the rerendering problem go away but then this Expression checked problem arisies .
Here the watchValueChange is the directive Input and selector and grid is the ngx datatable component where as the container Div is the view Child for the whole parent div i:e h-1oo
The thing is that the offset width is changing too fast before the cd can act on it and it causes the error . I tried to make use of Observable.of in the component to take the latest value and not take all values of the change but none work any idea please help
what i tried
@Directive({
selector: '[watchValueChange]'
})
export class watchDirective {
@Output() onValueChange = new EventEmitter<any>();
@Input('watchValueChange') public valueChange: any = null;
private changeEvent: Subject<any> = new Subject<any>();
constructor(private elRef: ElementRef) {}
ngOnInit() {
Observable.of(this.valueChange).debounceTime(100).subscribe(data => this.onValueChange.emit(data));
/*this.changeEvent.asObservable().debounceTime(300).subscribe(value => {
this.onValueChange.emit(value);
});*/
}
ngOnChanges(changes){
//this.changeEvent.next(this.valueChange);
}
}