无法实例化模块,AngularJS + NodeWebkit

Failed to instantiate module, AngularJS + NodeWebkit

我尝试使用 Node-Webkit 和 AngularJS 制作一个独立的网络应用程序。

我遵循 AngularJS.org 教程,但在尝试创建 angular 模块时遇到错误。

Error: [$injector:modulerr] Failed to instantiate module hecktelionApp due to:

Error: [$injector:nomod] Module 'hecktelionApp' 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.

我的项目层次结构如下:

root-app-folder
├── index.html
├── package.json
├── js\
│   └── app.js
└── node_modules\
    └── angular\

这是我的文件

index.html

<!DOCTYPE html>
<html ng-app="hecktelionApp">
    <head>
        <title>Hecktelion : Legacy</title>
        <script src="js/app.js"></script>
    </head>
    <body>
        <p>Hello world !</p>
    </body>
</html>

app.js

'use strict';

global.document = window.document;

var angular = require('angular');
var hecktelionApp = angular.module('hecktelionApp', []);

package.json

{
  "name": "Hecktelion",
  "main": "index.html",
  "author": "Toxicat <marc.guilmard@gmail.com>",
  "window": {
    "toolbar": false,
    "width": 1280,
    "height": 1024
  },
  "dependencies": {
    "angular": "^1.3.14"
  }
}

我哪里做错了?

看起来 window 没有按照要求 angular 的方式正确定义。

您可以将您的代码包装在一个匿名函数中,然后将 window 注入其中。

(function() {
    var angular = require('angular');
    var hecktelionApp = angular.module('hecktelionApp', []);
}).bind(window);