angularjs - Uncaught Error : Module name "electron" has not been loaded yet for context: _. 使用 require([])

标签 angularjs electron electron-builder

我正面临这个错误:
Uncaught Error :尚未为上下文加载模块名称“Electron ”:_。使用要求([])

$scope.sendWhatsapp = function (report) {

let url = 'https://wa.me/91' + report.patient_phone_no + '?text=Hi, Your report is ready. Please visit the laboratory to collect it.'
console.log(typeof window.require);

if (typeof window.require === 'function') {
    const shell = window.require('electron')

    shell.openExternal(url);
}
}
提前致谢

最佳答案

只需设置一个全局变量并在 Angular 组件中访问它

**main.js**
app.whenReady().then(() => {`
let mainWindow = new BrowserWindow({`
    webPreferences: {
        preload: path.join(__dirname, 'preload.js'),
        contextIsolation: true
    },
    width:640,
    height: 480,
    resizable: false
})
... rest of code
**preload.js**
const { contextBridge, shell} = require('electron')
contextBridge.exposeInMainWorld(
'electron',
{
    shell: shell
})

关于angularjs - Uncaught Error : Module name "electron" has not been loaded yet for context: _. 使用 require([]),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66505501/

相关文章:

javascript - 我的带有create-react-app的 Electron 应用出现错误

javascript - Promise 子进程通信

node.js - 程序列表中的 Electron 生成器应用程序名称没有 Windows 版本

node.js - Angular + Electron - 找不到模块 main.js

javascript - 如何使用 typescript 在 Ionic 2.0 中包含 Angular 模式形式

Angularjs $state.go 在新标签页中打开链接

php - 如何将 Angular Datepicker UI 值插入 MySQL 列?

angularjs - 不断检查LocalStorage

reactjs - 如何在 React 功能组件中模拟 ipcRenderer.on 功能