I have created an angular 6 project using the angular-cli.
Following that that I have installed Electron and done this:
changed src/index.html base to
Installed Electron locally:
npm install electron --save-dev
Created a main.js file on the root of my project
const { app, BrowserWindow } = require('electron')
let win;
function createWindow () { win = new BrowserWindow({ width: 600, height: 600, })
win.loadURL(
file://${__dirname}/dist/myproject/index.html
)win.on('closed', function () { win = null }) }
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') { app.quit() } })
app.on('activate', function () { if (win === null) { createWindow() } })
Adjusted the package.json file
{ "name": "angular-electron", "version": "0.0.0", "license": "MIT", "main": "main.js", // <-- update here "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "electron": "electron .", // <-- run electron "electron-build": "ng build --prod && electron ." // <-- build app, then run electron }, // ...omitted }
If I now run
npm run electron-build
The project will work.
My problem now is that I have created a renderer.js file and want to execute functions there from my angular component
For example:
renderer.js
function somefunction() {
// do something
}
app.component.html
<button (click)="somefunction()">Run Function in renderer.js</button>
How can I do this?