Ita*_*snt 14 rest angularjs 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 },
})
});
Run Code Online (Sandbox Code Playgroud)
控制器(controller.js)
var app = angular.module('ngdemo.controllers', []);
app.controller('ProviderListCtrl', ['$scope', 'ProvidersFactory', '$location',
function ($scope, ProvidersFactory, $location) {
$scope.providers = ProvidersFactory.query();
}]);
Run Code Online (Sandbox Code Playgroud)
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' });
}]);
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
Rus*_*iev 23
尝试在Safari浏览器中调试.对我来说,它获得了有关此错误的更多信息.在我的情况下,我使用angular-seedapp并将' myApp '模块重命名为' myNameOfAppApp '.我收到此错误Safari:
错误:[$ injector:modulerr]由于以下原因无法实例化myApp模块:[$ injector:nomod]模块'myApp'不可用!您要么错误拼写了模块名称,要么忘记加载它.如果注册模块,请确保将依赖项指定为第二个参数.
我尝试通过' mayApp '关键词找到并在index.html中重命名后修复错误.