Angular error in MEAN stack - Uncaught Error: $injector:modulerr
Angular error in MEAN stack - Uncaught Error: $injector:modulerr
我正在做一个简单的 MEAN 堆栈,代码一开始就很好,当我多写几行代码时 Angular 显示错误。我做错了什么?对于这个问题,我无法跟随 Internet MEAN 堆栈课程。
请帮助解决这个问题。
Html Code of index.
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Contact list App</title>
<link rel="stylesheet" href="css/metro-bootstrap.min.css" />
</head>
<body>
<div class="container" ng-controller="AppCtrl">
<section class="row">
<div class="col-lg-12 text-center">
<h1>This is a MEAN stack - Contact list!</h1>
<table class="table">
<thead>
<tr>
<th class="text-center">Name</th>
<th class="text-center">Email</th>
<th class="text-center">P. Number</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contactist">
<td>{{contact.name}}</td>
<td>{{contact.email}}</td>
<td>{{contact.number}}</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/metro-docs.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"></script>
<script type="text/javascript" src="controllers/controller.js"></script>
</body>
Controller
var myApp = angular.module('myApp', ['ngRoute']);function AppCtrl($scope, $http) {
console.log("Hello world from controller.js");
$http.get('/contactlist').success(function (response) {
console.log("I got the data");
$scope.contactList = response;
});}
Server
var express = require('express');
var app = express();
app.use(express.static(__dirname + "/public"));
app.get('/contactList', function (req, res) {
console.log("I got the request!");
person1 = {
name: 'Tim',
email: 'tim@domain.com',
number: '(111) 11-11-111'
};
person2 = {
name: 'Rod',
email: 'rod@domain.com',
number: '(211) 11-11-111'
};
person3 = {
name: 'Eddie',
email: 'eddie@domain.com',
number: '(311) 11-11-111'
};
res.json([person1, person2, person3]);
});
app.listen(3000);
console.log("Server running from port 3000");
This is the error: Uncaught Error: [$injector:modulerr]
[AngularJs Error]1
看起来您的控制器似乎没有连接 - 您已经声明了该功能,但没有告诉 angular。试试这个:
var myApp = angular.module('myApp', ['ngRoute'])
myApp.controller('AppCtrl', function($scope, $http) {
console.log("Hello world from controller.js");
$http.get('/contactlist').success(function (response) {
console.log("I got the data");
$scope.contactList = response;
});
});
我也没有看到脚本标签加载的迹象 angular,但它必须在那里才能获得错误消息。您是否还记得包括 ngRoute,例如?
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-route.js"></script>
我正在做一个简单的 MEAN 堆栈,代码一开始就很好,当我多写几行代码时 Angular 显示错误。我做错了什么?对于这个问题,我无法跟随 Internet MEAN 堆栈课程。 请帮助解决这个问题。
Html Code of index.
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Contact list App</title>
<link rel="stylesheet" href="css/metro-bootstrap.min.css" />
</head>
<body>
<div class="container" ng-controller="AppCtrl">
<section class="row">
<div class="col-lg-12 text-center">
<h1>This is a MEAN stack - Contact list!</h1>
<table class="table">
<thead>
<tr>
<th class="text-center">Name</th>
<th class="text-center">Email</th>
<th class="text-center">P. Number</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contactist">
<td>{{contact.name}}</td>
<td>{{contact.email}}</td>
<td>{{contact.number}}</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/metro-docs.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"></script>
<script type="text/javascript" src="controllers/controller.js"></script>
</body>
Controller
var myApp = angular.module('myApp', ['ngRoute']);function AppCtrl($scope, $http) {
console.log("Hello world from controller.js");
$http.get('/contactlist').success(function (response) {
console.log("I got the data");
$scope.contactList = response;
});}
Server
var express = require('express');
var app = express();
app.use(express.static(__dirname + "/public"));
app.get('/contactList', function (req, res) {
console.log("I got the request!");
person1 = {
name: 'Tim',
email: 'tim@domain.com',
number: '(111) 11-11-111'
};
person2 = {
name: 'Rod',
email: 'rod@domain.com',
number: '(211) 11-11-111'
};
person3 = {
name: 'Eddie',
email: 'eddie@domain.com',
number: '(311) 11-11-111'
};
res.json([person1, person2, person3]);
});
app.listen(3000);
console.log("Server running from port 3000");
This is the error: Uncaught Error: [$injector:modulerr] [AngularJs Error]1
看起来您的控制器似乎没有连接 - 您已经声明了该功能,但没有告诉 angular。试试这个:
var myApp = angular.module('myApp', ['ngRoute'])
myApp.controller('AppCtrl', function($scope, $http) {
console.log("Hello world from controller.js");
$http.get('/contactlist').success(function (response) {
console.log("I got the data");
$scope.contactList = response;
});
});
我也没有看到脚本标签加载的迹象 angular,但它必须在那里才能获得错误消息。您是否还记得包括 ngRoute,例如?
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-route.js"></script>