首页 > 解决方案 > Angular Electron 从组件调用服务(类型错误:getSources 不是函数)

问题描述

我正在使用 Angular 12 和电子。

我在服务中有一个方法,如下所示:

在我的服务中:

const desktopCapturer = (window as any).require('electron');

...

getDesktopCaptureSources(options: any) {
    return new Promise((resolve, reject) => {
     desktopCapturer.getSources(options).then((sources: any[]) => {
      return resolve(sources.map(source => {
       return {
        id: source.id,
        name: source.name,
        url: source.thumbnail.toDataURL()
       };
      }));
     });
    });
   }

在我的组件上,我正在调用该方法来尝试获取一些输出:

screenshot() {
    let options = { types: ['screen'], thumbnailSize: 200 };
    console.log(this.electronService.getDesktopCaptureSources(options));
}

但控制台只是返回:

ERROR Error: Uncaught (in promise): TypeError: eE.getSources is not a function
TypeError: eE.getSources is not a function

我怎样才能解决这个问题?

标签: angulartypescriptelectronangular12

解决方案


推荐阅读