gpt4 book ai didi

javascript - Angular 和 NodeJS 模块 'foo' 不可用

转载 作者:搜寻专家 更新时间:2023-11-01 00:16:56 26 4
gpt4 key购买 nike

我觉得我快疯了,因为答案应该很简单,我是 angular 和 nodejs 的新手,我正在尝试制作一个将它们结合起来的应用程序。

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

公共(public)/ Controller /家庭 Controller :

(function () {
'use strict';
angular.module('myApp').controller('homeController', homeController);

function homeController() {
var vm = this;
vm.fillerData = "FillerData"
}
}) ();

public/Index.html:

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Dit is de index</title>
<script src="res/js/angular.js" type="text/javascript" defer="defer"></script>
<script src="controllers/homeController.js" type="text/javascript" defer="defer"></script>
</head>
<h1>What</h1>
<body ng-controller="homeController as homeCtrl">
{{ homeCtrl.fillerData }}
</body>
</html>

路由器/index.js:

var router = require('express').Router();

router.get('/index', function (req, res) {
res.sendfile('public/index.html');
});
router.get('/home', function (req, res) {
res.sendfile('public/home.html');
});
module.exports = router;

和/server.js:

var express  = require('express');
var app = express();
var routes = require('./router');

app.use(express.static(__dirname + '/public'));

app.use('/', routes);
require('router/index.js')(app);

app.listen(3000);
console.log("App listening on port 3000");

所有必要的软件包也已安装,如有任何帮助,我们将不胜感激

最佳答案

如果你想创建一个新的module,你需要传递一个空的array作为第二个参数(如果你对其他模块有依赖,而不是告诉模块在数组中),这将告诉 Angular 您正在创建一个新模块。

来自Documentation

Beware that using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module.

angular.module('myApp',[]).controller('homeController', homeController);

如果你想获得已经创建的模块,那么你需要像这样调用

angular.module('myApp',[])....

关于javascript - Angular 和 NodeJS 模块 'foo' 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41933785/

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