angularjs - Chrome 上的未捕获对象错误。 Angularjs + ngResource

标签 angularjs rest ngresource

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

最佳答案

尝试在 Safari 中调试浏览器。对我来说,它可以获得有关此错误的更多信息。在我的情况下,我使用 angular-seed应用程序并重命名 ' 我的应用程序 '模块到' myNameOfAppApp '。
我在 Safari 中收到此错误:

Error: [$injector:modulerr] Failed to instantiate module myApp due to: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.



我尝试通过 ' 查找mayApp ' 关键字和重命名后 index.html 错误已修复。

关于angularjs - Chrome 上的未捕获对象错误。 Angularjs + ngResource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23898113/

相关文章:

angularjs - 如何在angularjs中禁用自动注入(inject)器(注入(inject)器类型的神奇发现)?

javascript - 如何更改动态 AngularJS ng 类中字形的颜色?

performance - 你会为了性能而违背 REST 的幂等性原则吗?

AngularJS:无法使用 $resource 发送 PUT 请求

javascript - Angular 表 ng-repeat

javascript - 似乎没有使用元素中传入的选项执行 Angular 指令

java - 在 REST Web 服务中接受逗号分隔值

java - 实体模型或Pojo类作为REST API的返回对象

angularjs - 如何使用 Angular 资源 TransformRequest GET 参数?

javascript - 绑定(bind)输入与 ngResource get() 搜索与 AngularJS