我试图通过ViewChild获取ConsultaAuditorGridComponent的实例,并且ViewChildren总是返回'Undefined'
............................................... ................................................... ................................................... ...........
export class ModalConsultaComponent implements OnInit, AfterViewInit {
public data: Array<any>;
closeResult: string;
@ViewChild('content')
content: any;
@ViewChildren(ConsultaAuditorGridComponent)
grid: QueryList<ConsultaAuditorGridComponent>;
//@ViewChild('grid') grid: ConsultaAuditorGridComponent;
public modal: NgbModalRef;
public form: FormGroup;
columns: any[] =
[
{text: 'Cod. Auditor', datafield: 'f_codigo_usuario', width: '35%'},
{text: 'Nombre', datafield: 'f_nombre', width: '65%'},
];
source: any = {};
dataAdapter: any;
constructor(
private modalService: NgbModal,
private asignacionService: AsignacionService,
private fb: FormBuilder,
) {
this.form = this.fb.group({
f_codigo_usuario: [''],
f_nombre: ['']
});
// this.asignacionService.getAuditorList().subscribe(data => {
// this.source = {
// localdata: [],
// datatype: 'json',
// datafields: [
// {name: 'f_id', type: 'int'},
// {name: 'f_codigo_usuario', type: 'int'},
// {name: 'f_nombre', type: 'string'},
// ],
// };
// this.dataAdapter = new jqx.dataAdapter(this.source);
// });
}
ngAfterViewInit() {
console.log(this.content)
}
generate() {
this.modal = this.modalService.open(this.content, {container: 'body', ariaLabelledBy: 'modal-basic-title', centered: true});
}
private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
ngOnInit(): void {
//console.log(this.modal.componentInstance.grid)
}
public open() {
this.generate();
}
public buscar() {
this.asignacionService.getAuditorList().subscribe( data => this.grid.first.setData(data))
}
}
............................................... ................................................... ................................................... ......