Angular2如何触发(单击)事件

时间:2018-06-13 13:14:07

标签: html angular ionic2

我有divion-input #fileInput type="file" accept="image/*" id="fileInput" [(ngModel)]="imageFilePath" (ionChange)="imageFilePath_change($event)" ></ion-input>

如何使用ion-input

模拟div组件上的点击

我的HTML代码是:

<div (click) = "fileInput.click()">
    <img src="assets/img/camera_button.png" [ngStyle]="{'position': 'fixed', 'top': '30vw', 'left': '32vw', 'height': '30px', 'color': '#0080FF'}">
    <ion-input #fileInput type="file" accept="image/*" id="fileInput" [(ngModel)]="imageFilePath" (ionChange)="imageFilePath_change($event)" ></ion-input>
    <span [ngStyle]="{'position': 'fixed', 'top': '32vw', 'left': '42vw', 'color': '#0080FF'}">{{ 'addMorePhotosBtn' | translate }}</span>
</div>

错误是:

TypeError: jit_nodeValue_20(...).click is not a function

1 个答案:

答案 0 :(得分:1)

这是我点击div时文件的工作示例。

Html文件

TextBlock

打字稿文件

 <ion-list>
       <ion-item (click)="onImageClick()">
           <div>
              <ion-icon ios="ios-add-circle" md="md-add-circle"></ion-icon>
                  Add Files
              </div>
       </ion-item>
   </ion-list>

为我测试完美。

相关问题