我正在开发一个使用 Angular 5 的 Electron 应用程序。我有一个文件上传代码
<input type="file" name="logochange" id="change-logo" accept="image/png, image/jpg" (change)="changeLogo()" />
以及如下TS文件中的changeLogo()函数
changeLogo() {
alert('logo changed');
}
问题:如果我运行“ng serve”并从浏览器进行测试,则会触发“change”事件。但是如果我制作 Electron 应用程序(npm 运行 Electron 窗口)。相同的“更改”事件未触发。为什么它在正常 Angular 下工作而在 Electron 下却不行?
我们将不胜感激。
最佳答案
引用:https://blog.angular-university.io/how-does-angular-2-change-detection-really-work/
添加更改检测器: 可能是您的代码在使用 electron 时位于外 Angular 区域
import {ChangeDetectorRef} from '@angular/core';
constructor( private ref: ChangeDetectorRef) {
this.ref.detectChanges();
}
关于javascript - Angular Electron - 更改事件不会触发文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52941491/