提问者:小点点

Angular/Electronic使用带有角度分量的renderer.js


我已经使用angular-CLI创建了一个angular 6项目。

在此之后,我安装了Electronic并完成了以下操作:

>

  • 将src/index.html基更改为

    null

    本地安装的电子:

    npm安装电子--保存-开发

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

    const{app,BrowserWindow}=require(“electronic”)

    让胜利;

    函数createWindow(){win=新的BrowserWindow({width:600,height:600,})

    win.loadurl(文件://${__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()}})

    调整了package.json文件

    {“名称”:“Angular-Electronic”,“版本”:“0.0.0”,“许可证”:“MIT”,“Main”:“Main.js”,//<--此处更新“脚本”:{“NG”:“NG”,“Start”:“NG serve”,“build”:“NG build”,“Test”:“NG Test”,“Lint”:“NG Lint”,“E2E”:“NG E2E”,“Electronic”:“NG build--Prod&Electronic”,//<--构建app,然后运行Electronic},//。。。省略}

    如果我现在参选

    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>
    

    我怎么能这么做呢?


  • 共1个答案

    匿名用户

    因为您使用的是Angular,所以不需要renderer.js,您应该在app.component.ts中添加您的函数。

    话虽如此,如果您仍然需要renderer.js,那么您有没有将该文件添加到您的index.html中

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

    这将使其在全球范围内都可以访问。