import {Component, OnInit, ViewChild} from '@angular/core'; @Component({ selector: 'app-demo-select', template: `

{{result1}} {{result2}}

`, styles: [``] }) export class DemoSelectComponent implements OnInit { default: any; result1: any; result2: any; data: any; @ViewChild('mySelect') select; @ViewChild('mySelect2') select2; @ViewChild('mySelect3') select3; //@ViewChildren(SelectComponent) selectCmps: QueryList; constructor() { } resetData() { // this.default = null; //this.setData(); // this.default = this.data[1]; // this.defaultValue = this.data[2].field; // this.select.changeCurrentValue(); // this.select2.changeCurrentValue(); // this.select3.changeCurrentValue(); this.select.clearValue(); // 清除select当前选中/输入的数据 this.select2.clearValue(); this.select3.clearValue(); } ngOnInit() { this.setData(); setTimeout(() => { this.default = this.data[1]; }, 1000); } // 失去焦点事件 selectBlurEvent(ev) { console.log(ev); } showResult1(event) { this.result1 = JSON.stringify(event); console.log(event); } showResult2(event) { this.result2 = JSON.stringify(event); } setData() { this.data = [{ field: 'aadsfds', title: 'th1', width: '50%' }, { field: '312', title: 'th2', width: '10%' }, { field: 'field3field3field3field3field3', title: 'th3', width: '20%', canSort: true }, { field: 'asdtqrgg', title: 'opration', canSort: true, width: '20%', }, { field: 'hello', title: 'opra2tion', canSort: true, width: '20%', }, { field: 'world', title: 'oprat1ion', canSort: true, width: '20%', }, { field: 'rock', title: 'opratio1n1', canSort: true, width: '20%', }, { field: 'howard', title: 'opration', canSort: true, width: '20%', }, { field: 'hollywood', title: 'opration', canSort: true, width: '20%', }]; } }