我在调用webservice请求时收到此错误。我正在使用restangular.js文件。我正在调用webservice。但是在调用webservice时我收到错误。请你帮我删除
这是我的代码
我正在阅读这里的文档 https://github.com/mgonto/restangular#element-methods
Uncaught Error: [$injector:nomod] http://errors.angularjs.org/1.3.3/$injector/nomod?p0=app
angular.min.js:101 Error: [ng:areq] http://errors.angularjs.org/1.3.3/ng/areq?p0=IndexCtrl&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:6:416
at Ob (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:19:417)
at pb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:20:1)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:75:177
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:57:112
at r (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:7:408)
at F (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:56:496)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:51:299)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:51:316)
答案 0 :(得分:0)
IndexCtrl未定义。要修复错误,请定义IndexCtrl。您无法使用console.debug,因为对服务的调用将是异步的。现在只需将结果分配给范围
var IndexCtrl = function ($scope, Restangular){
$scope.data = Restangular.all("data").getList().$object;
};
angular
.module('app')
.controller('IndexCtrl', IndexCtrl);
IndexCtrl.$inject = ['$scope', "Restangular"];
您的服务也存在问题,因为我得到了另一个服务网址:
angular.module('app',["restangular", "ngRoute"])
.config(function (RestangularProvider) {
RestangularProvider.setBaseUrl('http://jsonplaceholder.typicode.com');
});