【问题标题】:Angular / Electron using the renderer.js with angular componentsAngular / Electron 使用带有角度组件的 renderer.js
【发布时间】:2018-11-22 05:18:06
【问题描述】:

我使用 angular-cli 创建了一个 angular 6 项目。

在我安装了 Electron 并完成此操作之后:

  1. 将 src/index.html 基础更改为

  2. 在本地安装 Electron:

    npm install electron --save-dev

  3. 在我的项目的根目录上创建了一个 main.js 文件

    const { app, BrowserWindow } = require('electron')

    让我们赢;

    函数创建窗口(){ 赢=新浏览器窗口({ 宽度:600, 身高:600, })

    win.loadURL(file://${__dirname}/dist/myproject/index.html)

    win.on('关闭', function () { 赢=空 }) }

    app.on('ready', createWindow)

    app.on('window-all-close', function () {

    if (process.platform !== 'darwin') { app.quit() } })

    app.on('激活', function () { 如果(赢===空){ 创建窗口() } })

  4. 调整了package.json文件

    { “名称”:“角电子”, “版本”:“0.0.0”, “许可证”:“麻省理工学院”, "main": "main.js", //

如果我现在跑步

npm run electron-build

该项目将起作用。

我现在的问题是我创建了一个 renderer.js 文件并希望从我的 angular 组件中执行函数

例如:

renderer.js

function somefunction() {
    // do something
}

app.component.html

<button (click)="somefunction()">Run Function in renderer.js</button>

我该怎么做?

【问题讨论】:

    标签: angular typescript electron angular-cli angular6


    【解决方案1】:

    没有必要 renderer.js,因为您使用的是 angular。您应该在 app.component.ts 中添加您的函数。

    话说如果你还需要renderer.js,你有没有把文件添加到你的index.html中

      require('./somePath/dist/renderer.js')
    

    这将使其全球可访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 2020-02-15
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      相关资源
      最近更新 更多