gpt4 book ai didi

javascript - 无法实例化模块,AngularJS + NodeWebkit

转载 作者:行者123 更新时间:2023-12-03 10:41:48 25 4
gpt4 key购买 nike

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

我遵循 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 注入(inject)其中。

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

关于javascript - 无法实例化模块,AngularJS + NodeWebkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28743686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com