Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么会出现错误:[$injector:modulerr]http://errors.angularjs.org/1.6.5/$injector/moduler?_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 为什么会出现错误:[$injector:modulerr]http://errors.angularjs.org/1.6.5/$injector/moduler?

Javascript 为什么会出现错误:[$injector:modulerr]http://errors.angularjs.org/1.6.5/$injector/moduler?,javascript,html,angularjs,Javascript,Html,Angularjs,我正在尝试使用MVC5和AngularJS从SQL数据库加载数据。后端代码工作正常,我可以获取数据,但没有将其填充到我的表中 My Index.cshtml如下所示: @{ ViewBag.Title = "Index"; } <h2>Index</h2> <div ng-app="myapp"> <div ng-controller="StudentCtrl"> <table class="table t

我正在尝试使用MVC5和AngularJS从SQL数据库加载数据。后端代码工作正常,我可以获取数据,但没有将其填充到我的表中

My Index.cshtml如下所示:

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<div ng-app="myapp">
    <div ng-controller="StudentCtrl">
        <table class="table table-striped table-bordered table-hover table-checkable datatable">
            <thead class="grid-top-panel">
                <tr>
                    <th>StudentID</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Email</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="dataModel in students">
                    <td>{{dataModel.StudentID}}</td>
                    <td>{{dataModel.FirstName}}</td>
                    <td>{{dataModel.LastName}}</td>
                    <td>{{dataModel.Email}}</td>
                </tr>  
            </tbody>
        </table>
    </div>
</div>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/ScriptsNg/Module/app.js"></script>
<script src="~/ScriptsNg/Controller/StudentController.js"></script>
<script src="~/ScriptsNg/Services/StudentService.js"></script> 
StudentService.js:

app.service('StudentService', function ($http) {
    //**********----Get All Record----***************  
    var urlGet = '';
    this.getAll = function (apiRoute) {
        urlGet = apiRoute;
        return $http.get(urlGet);
    }
});
StudentController.js:

app.controller('StudentCtrl', ['$scope', 'StudentService',
    // we inject StudentService  inject because we call getAll method for get all student  
    function ($scope, StudentService) {
        // this is base url   
        var baseUrl = '/api/student/';
        // get all student from databse  
        $scope.getStudents = function () {
            var apiRoute = baseUrl + 'GetStudents/';
            var _student = StudentService.getAll(apiRoute);
            _student.then(function (response) {
                $scope.students = response.data;
            },
                function (error) {
                    console.log("Error: " + error);
                });

        }
        $scope.getStudents();

    }]);
一些帖子建议我在索引页上添加angular route脚本,并将ngRouter库注入我的模块。我做到了,但我仍然得到同样的错误:

错误:[$injector:modulerr]$injector/modulerr


我可能做错了什么?

模块、控制器和服务脚本从错误的文件夹加载,因此无法通过。我将它们更改为从正确的脚本文件夹中引用

请在开发过程中使用非缩微angular.js,错误消息将更清晰感谢@devqon我将脚本更改为使用非缩微脚本,现在得到此错误:0x800a139e-JavaScript运行时错误:[$injector:modulerr]无法实例化模块myapp,原因是:错误:[$injector:nomod]模块“myapp”不可用!您要么拼错了模块名,要么忘记加载它。如果注册模块,请确保您将依赖项指定为第二个参数。在控制台中,您可以确认您的脚本都正确显示吗?谢谢@Mickers,我从错误的文件夹引用了我的脚本,因此它没有获取模块、控制器和服务脚本。数据现在正在通过。谢谢
app.controller('StudentCtrl', ['$scope', 'StudentService',
    // we inject StudentService  inject because we call getAll method for get all student  
    function ($scope, StudentService) {
        // this is base url   
        var baseUrl = '/api/student/';
        // get all student from databse  
        $scope.getStudents = function () {
            var apiRoute = baseUrl + 'GetStudents/';
            var _student = StudentService.getAll(apiRoute);
            _student.then(function (response) {
                $scope.students = response.data;
            },
                function (error) {
                    console.log("Error: " + error);
                });

        }
        $scope.getStudents();

    }]);