如果我的FileInput元素是在一个正常的股利,然后正常工作。 但是,如果我里面放置<ng-template></ng-template>
然后我得到它不确定的。
这里是我的代码:
HTML
<ng-template #content let-c="close" let-d="dismiss">
<div class="modal-header">
<h4 class="modal-title">Modal title</h4>
<button type="button" class="close" aria-label="Close" (click)="d('Cross click')"></button>
</div>
<div class="modal-body">
<form #documentsForm="ngForm" (ngSubmit)="onEditSubscriberDocumentsSubmit(documentsForm.value);documentsForm.reset()">
<input #fileInput type="file" #select name="document" [(ngModel)]="document" (click)="onDocUpload()" />
<input type="submit" value="Save" class="btn btn-success" [hidden]="addDocHidden">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="c('Close click')">Close</button>
</div>
</ng-template>
TS
import { Component, OnInit, ViewChild , ElementRef} from '@angular/core';
export class EditSubscriberComponent {
constructor(private http: Http, private route: ActivatedRoute, private router: Router, private modalService: NgbModal) { }
@ViewChild("fileInput") fileInput: ElementRef;
ngOnInit() {
console.log(this.fileInput)
// This is undefined. If I place the <input #fileInput type="file">
// in the main div,not under ng-template, then I am getting the
// desired output
}
}
请建议我如何从纳克模板访问ViewChild