2017-01-25 4 views
0

要素のリストを選択して、その値の1つにオプションの値を指定してフォーカスを合わせたいとします。* ngForループを取得できませんでした<md-option> @ViewChildrenを使用している要素

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 
} 

答えて

2

あなたはそれだselectBox

this.selects.changes.subscribe((option: QueryList <any>) => { 
    console.log(option); 
}); 
+0

QueryList上のサブスクリプションを置くことを考えることができます。ありがとうございました。最後の質問: 'QueryList'のタイプ' 'はそうですか? – kyw

+1

@kywここにはい、 'component'については、' Type'コンポーネント –

関連する問題