我想选择元素列表,以便在给出选项值的情况下随意关注其中一个元素。
select.component.template:
<md-select
[formControl]="selectFormControl"
(click)="detectKeys()"
[required]="isRequired"
[disabled]="isDisabled"
[attr.role]="'listbox'"
[attr.aria-labelledby]="placeholder"
placeholder="placeholder">
<md-option #selectBox *ngFor="let option of options" [value]="option.value">
{{option.description}}
</md-option>
</md-select>
select.component.ts:
export class UiSelectComponent implements OnInit, AfterViewInit {
....
@Input() options: Object[];
@ViewChildren('selectBox') selects: QueryList<any>;
....
}
ngAfterViewInit() {
console.log(this.selects.length); // comes up empty results
}
答案 0 :(得分:2)
您可以考虑将订阅放在QueryList
的{{1}}
selectBox