小编Ita*_*snt的帖子

Chrome上未捕获的对象错误.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 …
Run Code Online (Sandbox Code Playgroud)

rest angularjs ngresource

14
推荐指数
2
解决办法
2万
查看次数

标签 统计

angularjs ×1

ngresource ×1

rest ×1