javascriptjqueryangularjsangularjs-directiveangularjs-scope

how to remove error while calling server request


I am getting this error while calling the webservice request .I am using restangular.js file .I am tring to call webservice .But While calling webservice I am getting error .could you please help me remov

I am reading the documentation from here 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)

Solution

  • IndexCtrl is undefined. To fix the error define IndexCtrl. You can't use console.debug as the call to the service will be asynchronous. For now just assign the result to scope

    var IndexCtrl = function ($scope, Restangular){
        $scope.data = Restangular.all("data").getList().$object;
    };
    
    angular
        .module('app')
        .controller('IndexCtrl', IndexCtrl);
    
    IndexCtrl.$inject = ['$scope', "Restangular"];
    

    There was also a problem with your service not being restful so I got another service url that was:

    angular.module('app',["restangular", "ngRoute"])
    .config(function (RestangularProvider) {
        RestangularProvider.setBaseUrl('http://jsonplaceholder.typicode.com');
    });
    

    Plunkr