1.在你的组件的.html文件中有一个html元素
<input
type="file"
accept="image/*"
(change)="selectStoreEntrancePic($event)"
class="pic-input"
#myInput
/>//#myInput为自定义的选择器名字
2.在.ts文件中有viewChild,ElementRef的模块、
import { Component,OnInit,ViewChild,ElementRef } from "@angular/core";//ViewChild,ElementRef
3.使用viewChild修饰符
@ViewChild('myInput', { static: false }) myInput: ElementRef<HTMLInputElement>
4.获取dom(然后点击)
this.myInput.nativeElement.click();