2017-12-19 11 views

답변

2

는 DOM 요소를 식별하고 ViewChild으로 접근 할 필요가 이러한 속성에 액세스하려면 :

<mat-select #mySelect placeholder="Favorite food"> 
    <mat-option *ngFor="let food of foods" [value]="food.value"> 
     {{ food.viewValue }} 
    </mat-option> 
    </mat-select> 

component.ts

component.html을

import {Component, ViewChild} from '@angular/core'; 

@Component({ 
    selector: 'select-overview-example', 
    templateUrl: 'select-overview-example.html', 
    styleUrls: ['select-overview-example.css'], 
}) 
export class SelectOverviewExample { 
    @ViewChild('mySelect') mySelect; 
    foods = [ 
    {value: 'steak-0', viewValue: 'Steak'}, 
    {value: 'pizza-1', viewValue: 'Pizza'}, 
    {value: 'tacos-2', viewValue: 'Tacos'} 
    ]; 

    click() { 
    this.mySelect.open(); 
    } 
} 

View a working stackblitz here.

+0

감사합니다. – Bhavesh