2015-04-26 9 views
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' }); 

}]). controllore ('hsbccontroller', [ '$ portata', '$ http', '$ risorsa', function ($ portata, $ risorsa, $ http) {

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

}]);

+6

I parametri del controller non sono nello stesso ordine in cui sono stati dichiarati utilizzando la notazione array. Cambia la posizione di '$ risorsa' e' $ http'. –

+1

dovrebbe essere .controller ('hsbccontroller', ['$ scope', '$ http', '$ risorsa', funzione ($ scope, $ http, $ risorsa) { – Kop4lyf

+1

Cool, grazie al suo compagno di lavoro. lavorando in angularJs con Rest API. Grazie mille. –

risposta

28

È necessario modificare le posizioni di $ http e $ risorsa.

Come funziona angularJS, (se definito in questo modo), i tentativi angolari per far corrispondere le stringhe forniscono agli argomenti della funzione, in modo che sappia quale argomento è cosa. Questo è fondamentalmente lo scopo di minimizzazione, che effettivamente cambiare le variabili come illustrato di seguito .:

.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; 
    }); 
}]); 

ecco, angularjs sa che:

mezzo $ portata,

b è $ http,

ec è $ risorsa.

Nel tuo caso, in realtà stava provando "$ resource.get" e quindi dandoti l'errore. Ulteriore lettura controllare la nota sulla minimizzazione sulla data pagina doc: https://docs.angularjs.org/tutorial/step_05

0

A mio parere, è l'errore di posizione - .controller('hsbccontroller', ['$scope','$http','$resource', function($scope,$resource,$http).

giusta posizione - .controller('hsbccontroller', ['$scope', '$http','$resource', function($scope, $http, $resource):

.controller('hsbccontroller', ['$scope', '$http','$resource', function($scope, $http, $resource){ 
    $http.get('http://localhost:8080/1/').success(function(data) { 
    alert(data); 
     $scope.greeting = data; 
    }); 
} 

ho avuto un problema come te stesso, ma Zona tipo giusto può risolverlo.

Problemi correlati