【问题标题】:Angular error in MEAN stack - Uncaught Error: $injector:modulerrMEAN 堆栈中的角度错误 - 未捕获的错误:$injector:modulerr
【发布时间】:2016-06-01 14:28:54
【问题描述】:

我正在制作一个简单的 MEAN 堆栈,代码从一开始就很好,当我再编写几行代码时,Angular 向我显示了一个错误。我做错了什么?对于这个问题,我无法关注 Internet MEAN 堆栈课程。 请帮助解决这个问题。

索引的HTML代码。

<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>

控制器

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;
});}

服务器

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");

这是错误:未捕获的错误:[$injector:modulerr] [AngularJs 错误]1

【问题讨论】:

    标签: angularjs node.js mean-stack


    【解决方案1】:

    看起来你的控制器没有连接 - 你已经声明了这个函数,有点没有告诉角度它。试试这个:

    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;
       });
    });
    

    我也看不到脚本标签加载角度的迹象,但它必须在那里才能获得错误消息。您是否还记得包括 ngRoute,例如?

    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-route.js"></script>
    

    【讨论】:

    • 这是错误:未捕获的错误:[$injector:modulerr] errors.angularjs.org/1.3.12/$injector/…...gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.12%2Fangular.min.js%3A17%3A381)
    • 你能把它粘贴到你的问题中,这样我就知道了
    • 好的。您需要将 ngRoute 添加到脚本导入中
    • @RodolfoA.CalvoJaubert 你过得怎么样?
    • 效果很好!!没有错误了!我会在我的代码中尝试其他的东西,以确保代码可以正常工作。我必须导入 angular-route.min.js!
    猜你喜欢
    • 2015-03-29
    • 1970-01-01
    • 2016-07-23
    • 1970-01-01
    • 2017-06-14
    • 2014-09-28
    • 2016-11-03
    • 2016-11-16
    相关资源
    最近更新 更多