Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度应用程序在运行时会断开_Angularjs_Node.js_Electron - Fatal编程技术网

Angularjs 角度应用程序在运行时会断开

Angularjs 角度应用程序在运行时会断开,angularjs,node.js,electron,Angularjs,Node.js,Electron,我开始构建一个电子应用程序,当我尝试运行内部的角度分布时遇到了一些问题 对于angular应用程序,我使用yeoman和grunt进行构建。如果我用grunt-serve开发angular应用程序,并在localhost:9000上运行它,Electron应用程序就可以很好地启动该应用程序。然而,如果我运行grunt build并将Electron应用程序指向静态文件,我会得到一些角度错误 [$injector:modulerr] Failed to instantiate module cli

我开始构建一个电子应用程序,当我尝试运行内部的角度分布时遇到了一些问题

对于angular应用程序,我使用yeoman和grunt进行构建。如果我用
grunt-serve
开发angular应用程序,并在localhost:9000上运行它,Electron应用程序就可以很好地启动该应用程序。然而,如果我运行grunt build并将Electron应用程序指向静态文件,我会得到一些角度错误

[$injector:modulerr] Failed to instantiate module clientApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngResource due to:
Error: [$injector:nomod] Module 'ngResource' is not available! You either
misspelled the module name or forgot to load it. If registering a module 
ensure that you specify the dependencies as the second argument.
在electron应用程序中,我使用express运行服务器,我还尝试通过本地主机8000上的express运行angular应用程序。那也没用。我还试着运行另一个angular应用程序,它部署在我的服务器上,只在浏览器中运行——在Electron中不运行。所有尝试都会出现相同的错误

我还必须提到,在所有情况下,如果我在浏览器中打开angular应用程序,它都可以正常工作

这是电子代码:

app.on('ready', function() {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 1024, height: 764, title: "uMaster"});

  // and load the index.html of the app.
  var url = path.join(__dirname, "dist", "index.html");
  url = "file://" + url;
  console.log(url);

  // mainWindow.loadURL(url); ---- this is not working in Electron
  // mainWindow.loadURL("http://localhost:8000"); -- not working when served by express
  mainwindow.loadURL("http://localhost:9000"); // working when angular runs with grunt serve

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });

  /* ----------------------- */
});

通过使用
nodeIntegration:false
初始化electron的
BrowserWindow
修复了此问题

mainWindow = new BrowserWindow({width: 1024, height: 764, title: "app", webPreferences: {"nodeIntegration":false}});

你的回答是正确的。如果您想维护节点集成,也可以在加载任何其他脚本之前,在
index.html
中使用以下代码:

<script>
  window.nodeRequire = require;
  delete window.require;
  delete window.exports;
  delete window.module;
</script>

window.nodeRequire=require;
删除window.require;
删除window.exports;
删除window.module;

听起来好像您错过了对
angular resource.min.js的引用,不是这样,如果修改angular模块的顺序,它只会说第一个模块没有被引用,它崩溃了。参考文献显然在那里,因为它在电子之外运行。