I feel like I'm losing my mind because the answer should be so simple, I'm new to angular and nodejs and I'm trying to make an application that combines them both.
我觉得我快疯了,因为答案应该很简单,我刚接触过角型和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."
错误:[$injector:nomod]模块‘myApp’不可用!您要么拼错了模块名,要么忘记加载它。如果注册一个模块,请确保将依赖项指定为第二个参数。
public/controllers/Homecontroller:
公共/控制器/ Homecontroller:
(function () {
'use strict';
angular.module('myApp').controller('homeController', homeController);
function homeController() {
var vm = this;
vm.fillerData = "FillerData"
}
}) ();
public/Index.html:
公共/ 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>
router/index.js:
路由器/ 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;
and /server.js:
和/ 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");
All the necessary packages have been installed as well, any help would be appreciated
所有必要的软件包也已经安装,任何帮助都将感激
3 个解决方案
#1
3
If you want to create a new module
, you need to pass an empty array
as the second parameter (if you have dependencies to other modules, than tell the modules in the array), which will tell angular that you are creating a new module.
如果您想要创建一个新的模块,您需要传递一个空数组作为第二个参数(如果您对其他模块有依赖关系,而不是告诉数组中的模块),这将告诉您正在创建一个新的模块。
From the 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.
注意,使用角。模块(' module ',[])将创建模块myModule,并覆盖任何名为myModule的现有模块。使用angular.module(myModule)检索现有模块。
angular.module('myApp',[]).controller('homeController', homeController);
If you want to get already created module, than you need to call like
如果您希望获得已经创建的模块,则需要调用like
angular.module('myApp',[])....
#2
3
Your module should have empty dependencies injected, change as
您的模块应该具有注入的空依赖项,更改为
angular.module('myApp',[]).controller('homeController', homeController);
#3
0
You have to change
你必须改变
angular.module('myApp').controller('homeController', homeController);
To:
:
angular.module('myApp', []).controller('homeController', homeController);
It will create the module.
它将创建模块。
#1
3
If you want to create a new module
, you need to pass an empty array
as the second parameter (if you have dependencies to other modules, than tell the modules in the array), which will tell angular that you are creating a new module.
如果您想要创建一个新的模块,您需要传递一个空数组作为第二个参数(如果您对其他模块有依赖关系,而不是告诉数组中的模块),这将告诉您正在创建一个新的模块。
From the 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.
注意,使用角。模块(' module ',[])将创建模块myModule,并覆盖任何名为myModule的现有模块。使用angular.module(myModule)检索现有模块。
angular.module('myApp',[]).controller('homeController', homeController);
If you want to get already created module, than you need to call like
如果您希望获得已经创建的模块,则需要调用like
angular.module('myApp',[])....
#2
3
Your module should have empty dependencies injected, change as
您的模块应该具有注入的空依赖项,更改为
angular.module('myApp',[]).controller('homeController', homeController);
#3
0
You have to change
你必须改变
angular.module('myApp').controller('homeController', homeController);
To:
:
angular.module('myApp', []).controller('homeController', homeController);
It will create the module.
它将创建模块。