在Chrome未捕获的对象错误。 Angularjs + ngResource [英] Uncaught object error on Chrome. Angularjs + ngResource

查看:171
本文介绍了在Chrome未捕获的对象错误。 Angularjs + ngResource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Chrome上调试,它不断显示出这样的错误:未捕获的对象,在angular.js:36

我是什么做错了吗? :/

感谢任何帮助:)

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

  VAR的服务= angular.module('ngdemo.services',['ngResource']);services.factory('ProvidersFactory',函数($资源){
    返回$资源('http://devfz.azurewebsites.net/api/providers/',{},{
        查询:{方法:GET,IsArray的:真正},
    })
});

控制器(controller.js)

  VAR应用= angular.module('ngdemo.controllers',[]);app.controller('ProviderListCtrl',['$范围,ProvidersFactory','$位置',
    功能($范围,ProvidersFactory,$位置){
        $ scope.providers = ProvidersFactory.query();
    }]);

app.js

  angular.module('ngdemo',['ngdemo.filters','ngdemo.services','ngdemo.directives','ngdemo.controllers'])。
配置(['$ routeProvider',函数($ routeProvider){
    $ routeProvider.when('/供应商名单,{templateUrl:/provider-list.html',控制器:'ProviderListCtrl'});
    $ routeProvider.otherwise({redirectTo:'/供应商名单'});
}]);

HTML

 <!DOCTYPE HTML>
< HTML NG-应用=ngdemo的xmlns =htt​​p://www.w3.org/1999/xhtml>
< HEAD>
    <标题>提供商与LT; /标题>
    <链接HREF =内容/ bootstrap.min.css的rel =stylesheet属性>
    <脚本SRC =脚本/供应商/ angular.min.js>< / SCRIPT>
    <脚本SRC =脚本/供应商/角resource.js>< / SCRIPT>
    &所述; SCRIPT SRC =controller.js>&下; /脚本>
    &所述; SCRIPT SRC =services.js>&下; /脚本>
    &所述; SCRIPT SRC =app.js>&下; /脚本>
< /头>
<车身的作用=文档的风格=填充顶:70像素;填充底:30PX>
    < D​​IV CLASS =箱体内容角色=主>
        < D​​IV NG控制器=ProviderListCtrl>
            < H2>提供商与LT; / H>
            <小时>
            < D​​IV的风格=宽度:60%>
                <表类=table表条纹表浓缩>
                    <&THEAD GT;
                        &所述; TR>
                            百分位风格=最小宽度:30PX;宽度:30PX;> ID和LT; /第i
                            百分位风格=最小宽度:100像素;>名称和LT; /第i
                        < / TR>
                    < / THEAD>
                    <&TBODY GT;
                        < TR NG重复=提供商提供商>
                            < TD VALIGN =中间>测试:{{provider.Id}}< / TD>
                            < TD VALIGN =中间>测试:{{provider.Name}}< / tdvalign>
                            < TD VALIGN =中间ALIGN =右WIDTH =40像素><一个NG点击=级=BTN BTN小BTN-主要>编辑< / A>< / TD>
                            < TD VALIGN =中间ALIGN =右WIDTH =50像素><一个NG点击=级=BTN BTN小BTN-危险>删除< / A>< / TD>
                        < / TR>
                    < / TBODY>
                < /表>
            < / DIV>
        < / DIV>
    < / DIV>
< /身体GT;
< / HTML>


解决方案

尝试 Safari浏览器浏览器进行调试。对于我来说,获得关于此错误的详细信息。在我来说,我使用角种子应用程序,并重新命名'对myApp '模块' myNameOfAppApp
我在收到此错误 Safari浏览器


  

错误:[$喷油器:modulerr]未能实例化模块对myApp由于:
  [$喷油器:NOMOD]模块'对myApp'不可!你要么
  拼写错误的模块名称,或忘了加载它。如果注册一个
  模块确保您指定的依赖作为第二
  参数。


我尝试找到' mayApp 键字和后重命名的 index.html的错误是固定的。

While using debug on Chrome, it keeps showing this error: uncaught object, on angular.js:36.

What am I doing wrong? :/

Thanks for any help :)

Module and Resource objects (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();
    }]);

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

解决方案

Try to debug in Safari browser. For me it get more information about this error. In my case I use angular-seed app and rename 'myApp' module to 'myNameOfAppApp'. I received this error in 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.

I try to find by 'mayApp' key word and after rename in index.html Error was fixed.

这篇关于在Chrome未捕获的对象错误。 Angularjs + ngResource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆