Reputation: 3015
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.
"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/controllers/Homecontroller:
(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>
router/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:
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
Upvotes: 2
Views: 138
Reputation: 18309
You have to change
angular.module('myApp').controller('homeController', homeController);
To:
angular.module('myApp', []).controller('homeController', homeController);
It will create the module.
Upvotes: 0
Reputation: 68675
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.
angular.module('myApp',[]).controller('homeController', homeController);
If you want to get already created module, than you need to call like
angular.module('myApp',[])....
Upvotes: 3
Reputation: 222722
Your module should have empty dependencies injected, change as
angular.module('myApp',[]).controller('homeController', homeController);
Upvotes: 3