角度模块未加载

时间:2016-03-01 14:08:35

标签: angularjs

所以我创建了一个带有单个控制器的新模块,保存在app目录下的controllers目录中:

var tables = angular.module('tables',[]).controller('setName', function ($scope) {
  $scope.userName = userName;
  $scope.userPassword = userPassword;
});

我有以下html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ang</title>

</head>
<script src="/socket.io-client/socket.io.js"></script>
<script src="/angular/angular.min.js"></script>
<body ng-app="tables">
  <div ng-controller="setName">
    User Name: <input type="text" ng-model="userName" ><br>
    Password: <input type="text" ng-model="userPassword" ><br><br>

    User Name: {{userName}}<br>
    Password: {{userPassword}}<br>

  </div>
</body>
</html>

我使用快递服务页面:

//Load express
var express = require('express');
//Load tables
//var tables = angular.module('table');
// Create express app
var app = express();
//Load http express wrapper
var http= require('http');
//Create variable for the port the server listens on
var srvPort = 3000;
//Make a static path to node_modules  directory
app.use(express.static('node_modules'));

app.use(express.static('controllers'));
//Make a static path to the public directory
app.use(express.static('public'));

app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
});


var server = http.createServer(app).listen(srvPort, function () {
    console.log('Server is listening on port ' + srvPort);
});

require('./public/javascript/sockets.js').initialize(server);

我收到以下错误:

Failed to instantiate module tables due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.5.0/$injector/nomod?  p0=tables
at Error (native)
at http://localhost:3000/angular/angular.min.js:6:416
at http://localhost:3000/angular/angular.min.js:25:136
at b (http://localhost:3000/angular/angular.min.js:24:188)
at http://localhost:3000/angular/angular.min.js:24:431
at http://localhost:3000/angular/angular.min.js:39:287
at n (http://localhost:3000/angular/angular.min.js:7:355)
at g (http://localhost:3000/angular/angular.min.js:39:135)
at fb (http://localhost:3000/angular/angular.min.js:43:164)
at Ac.c (http://localhost:3000/angular/angular.min.js:20:449

所以我的问题是,为什么我的模块没有加载?

任何帮助将不胜感激!

ž

1 个答案:

答案 0 :(得分:3)

您没有在<head>中加载它。您只有socket.io.jsangular.min.js,但没有包含模块的JS文件。