7
var hsbc = angular.module('hsbc',['ngResource','ngRoute']);

hsbc.config(['$routeProvider','$locationProvider', function ($routeProvider, $locationProvider){   

//console.log('config part working'); 
$routeProvider
    .when('/login', {
        controller: 'hsbccontroller',
        templateUrl: 'modules/authentication/views/login.html',
        hideMenus: true
    })
    .when('/gloabltranfer', {
        controller: 'hsbccontroller',
        templateUrl: 'modules/home/views/gloabltranfer.html'
    })
    .when('/tranferReq', {
        controller: 'hsbccontroller',
        templateUrl: 'modules/home/views/TransferRquest.html'
    })
    .when('/reviewdetail', {
        controller: 'hsbccontroller',
        templateUrl: 'modules/home/views/Reviewdetails.html'
    })
    .when('/confirmdetail', {
        controller: 'hsbccontroller',
        templateUrl: 'modules/home/views/confirmdetails.html'
    })

    .when('/', {
        controller: 'hsbccontroller',
        templateUrl: 'modules/authentication/views/login.html'
    })

    .otherwise({ redirectTo: '/login' });

}]).controller('hsbccontroller', ['$scope','$http','$resource', function($scope,$resource,$http){

    //console.log('controller part working'); 
    $http.get('http://localhost:8080/1/').success(function(data) {
        alert(data);
        $scope.greeting = data;
    });

}]);
3
  • 6
    Your controller's parameters are not in the same order that they were declared using the array notation. Change the position of $resource and $http. Commented Apr 26, 2015 at 14:19
  • 1
    it should be .controller('hsbccontroller', ['$scope','$http','$resource', function($scope,$http, $resource){ Commented Apr 26, 2015 at 14:20
  • 1
    Cool, Thanks its working buddy. Quite new to working in angularJs with Rest API. thanks a lot. Commented Apr 26, 2015 at 14:23

1 Answer 1

28

You need to change the positions of $http and $resource.

How angularJS works is, (if defined in this way), angular tries to match the strings provide to the arguments of the function, so that it knows which argument is what. This is basically for the purpose of minification, which will actually change the variables like illustrated below.:

.controller('hsbccontroller', ['$scope','$http','$resource', function(a,b,c){

    //console.log('controller part working'); 
a.get('http://localhost:8080/1/').success(function(data) {
    alert(data);
        $scope.greeting = data;
    });
}]);

so here, angularjs knows that:

a means $scope,

b is $http,

and c is $resource.

In your case, it was actually trying "$resource.get" and hence giving you the error. Further reading check the note on minification on the given doc page: https://docs.angularjs.org/tutorial/step_05

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.