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 the dom. And it always returns undefined
here is the select inside the main.html
<ng-select id="user-select"
#userSelect
[allowClear]="true"
[items]="singleSignOnUsers"
[disabled]="disabled"
placeholder="No user selected">
</ng-select>
here is my component
import { Component, AfterViewInit, ViewChild } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app-main',
templateUrl: '../app/main.html',
providers: [ApiHttpService, UserAdministrationService]
})
export class AppComponent {
@ViewChild('userSelect') userSelect;
ngAfterViewInit() {
alert(this.userSelect);
}
}
what am i missing here?
Update: Oh My Soul! I figured out why this wasn't working when this should.. I have the whole view wrapped in a div with an ngSwitch. If i move it out... I can access them. Now I don't know how to access them while in the ngSwitch however. But I can don't have to use the ngSwitch
<div [ngSwitch]='loading'>
<div *ngSwitchCase="false">
...
<ng-select id="user-select"
#userSelect
[allowClear]="true"
[items]="singleSignOnUsers"
[disabled]="disabled"
placeholder="No city selected">
</ng-select>
...
</div>
<div