I know this has been asked before, but none of the selected answers are working for me.
I am trying to use @ViewChild
to get my ng-select
from t
@twaldron Are you using some delayed data loading in ngOnInit?
Because in that case, in my experience, reading a @ViewChild as a ElementRef produces no results
If your component has the data already resolved (like the case when a parent passes a child data object to a sub component) it should work (at least for me it did).
In the case of asynchronous data loading, the way I was able to make it work is using a change notification
@ViewChildren('userSelect') userSelect: QueryList;
ngAfterViewInit(): void {
this.userSelect.changes.subscribe(item => {
if (this.userSelect.length) {
alert(this.userSelect.first.nativeElment.outerHTML)
}
})
}