Javascript 获取具有视图子元素的元素列表
我创建了一个genric表单,表单数组为angular 8 如果有Javascript 获取具有视图子元素的元素列表,javascript,angular,typescript,Javascript,Angular,Typescript,我创建了一个genric表单,表单数组为angular 8 如果有ViewChildid,我需要获取所有标签 但是当我控制台查看子对象时,它只显示一个元素,而不是元素列表,但我需要显示元素列表 有什么问题?我怎样才能解决这个问题? html: <ngx-mat-file-input #upload disabled="true" class="uploadFild" (change)="showPreview($event,i)" appearance="outline"
ViewChild
id,我需要获取所有标签
但是当我控制台
查看子对象时,它只显示一个元素,而不是元素列表,但我需要显示元素列表
有什么问题?我怎样才能解决这个问题?
html:
<ngx-mat-file-input #upload disabled="true" class="uploadFild" (change)="showPreview($event,i)" appearance="outline"
formControlName="file" type=file>
</ngx-mat-file-input>
改用
@ViewChildren
例如:
import {AfterViewInit, Component, Directive, QueryList, ViewChildren} from '@angular/core';
@Directive({selector: 'child-directive'})
class ChildDirective {
}
@Component({selector: 'someCmp', templateUrl: 'someCmp.html'})
class SomeCmp implements AfterViewInit {
@ViewChildren(ChildDirective) viewChildren !: QueryList<ChildDirective>;
ngAfterViewInit() {
// viewChildren is set
}
}
从'@angular/core'导入{AfterViewInit,Component,Directive,QueryList,ViewChildren};
@指令({选择器:'子指令'})
类ChildDirective{
}
@组件({selector:'someCmp',templateUrl:'someCmp.html'})
类实现AfterViewInit{
@ViewChildren(ChildDirective)ViewChildren!:QueryList;
ngAfterViewInit(){
//viewChildren已设置
}
}
检查文档:我看到了此文档,但它不起作用,因为我在
@ViewChildren
中使用了ngx mat文件输入
指令名帮助我解决问题。谢谢
import {AfterViewInit, Component, Directive, QueryList, ViewChildren} from '@angular/core';
@Directive({selector: 'child-directive'})
class ChildDirective {
}
@Component({selector: 'someCmp', templateUrl: 'someCmp.html'})
class SomeCmp implements AfterViewInit {
@ViewChildren(ChildDirective) viewChildren !: QueryList<ChildDirective>;
ngAfterViewInit() {
// viewChildren is set
}
}