14

在 Chrome 上使用调试时,它一直显示此错误:未捕获的对象,在 angular.js:36 上。

我究竟做错了什么?:/

谢谢你的帮助 :)

模块和资源对象 (services.js)

var services = angular.module('ngdemo.services', ['ngResource']);

services.factory('ProvidersFactory', function ($resource) {
    return $resource('http://devfz.azurewebsites.net/api/providers/', {}, {
        query: { method: 'GET', isArray: true },
    })
});

控制器(controller.js)

var app = angular.module('ngdemo.controllers', []);

app.controller('ProviderListCtrl', ['$scope', 'ProvidersFactory', '$location',
    function ($scope, ProvidersFactory, $location) {
        $scope.providers = ProvidersFactory.query();
    }]);

应用程序.js

angular.module('ngdemo', ['ngdemo.filters', 'ngdemo.services', 'ngdemo.directives', 'ngdemo.controllers']).
config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/provider-list', { templateUrl: '/provider-list.html', controller: 'ProviderListCtrl' });
    $routeProvider.otherwise({ redirectTo: '/provider-list' });
}]);

HTML

<!DOCTYPE html>
<html ng-app="ngdemo" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Providers</title>
    <link href="Content/bootstrap.min.css" rel="stylesheet">
    <script src="Scripts/Vendor/angular.min.js"></script>
    <script src="Scripts/Vendor/angular-resource.js"></script>
    <script src="controller.js"></script>
    <script src="services.js"></script>
    <script src="app.js"></script>
</head>
<body role="document" style="padding-top: 70px; padding-bottom: 30px">
    <div class="container body-content" role="main">
        <div ng-controller="ProviderListCtrl">
            <h2>Providers</h2>
            <hr>
            <div style="width:60%">
                <table class="table table-striped table-condensed">
                    <thead>
                        <tr>
                            <th style="min-width: 30px; width: 30px;">Id</th>
                            <th style="min-width: 100px;">Name</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="provider in providers">
                            <td valign="middle">Test: {{provider.Id}}</td>
                            <td valign="middle">Test: {{provider.Name}}</tdvalign>
                            <td valign="middle" align="right" width="40px"><a ng-click="" class="btn btn-small btn-primary">edit</a></td>
                            <td valign="middle" align="right" width="50px"><a ng-click="" class="btn btn-small btn-danger">delete</a></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>
4

2 回答 2

23

尝试在Safari浏览器中调试。对我来说,它可以获得有关此错误的更多信息。就我而言,我使用angular-seedapp 并将“ myApp ”模块重命名为“ myNameOfAppApp ”。我收到此错误Safari

错误:[$injector:modulerr] 无法实例化模块 myApp,原因是:[$injector:nomod] 模块“myApp”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

我尝试通过' mayApp ' 关键字查找,并在index.html中重命名错误后得到修复。

于 2014-06-01T13:04:21.733 回答
10

In order to use $routeProvider you need to include (and declare as a dependency) the ngRoute module.

See, this answer for more info.

于 2014-05-27T22:05:18.753 回答